58b Subj : Re: How to manage time-slicing in Pthreads programs? To : comp.programming.threads From : Joe Seigh Date : Sat Feb 19 2005 09:57 pm On 19 Feb 2005 18:01:22 -0800, D'artagnan wrote: > OK, maybe I didn't explain the situation clearly in my first post. In > my example, I don't want thread A to put itself to sleep, I want thread > B to put it to sleep and wake it up later. Consider the following > senario: thread A and thread B are processing a huge collection of > items, one-by-one. The workload is split up between the two threads > such that 99% chance there aren't conflicting accesses between the two > threads. For the 1% chance of conflicting accesses we need some > protection. The problem is that thread A never knows which items will > cause conflicting accesses, only thread B has this knowledge. > Therefore, pthread_cond_wait() doesn't apply here because (1) thead A > doesn't know when to wait; and (2) if thread B calls it and goes to > sleep, there is nobody to wake it up. > > The desired scheme would be: When thread B becomes aware of a potential > conflicting access, it puts thread A into sleep. Thread B finishes the > access, then wakes thread A up. Are there any ways to do this? Thanks. > > No, because there is no way for you to tell where thread A is and at what point it will sleep after you tell it to. -- Joe Seigh . 0