Subj : Re: why my threads do not wake up To : comp.programming.threads From : David Schwartz Date : Wed Aug 24 2005 11:45 am "Jingbo" wrote in message news:1124902430.818290.221850@f14g2000cwb.googlegroups.com... > DS, > I do not think you understand pthread_cond_wait correctly. It will not > wake up until pthread_cond_signal or pthread_cond_broadcase is called > on that condition variable that it is waiting on. You mean it is not *guaranteed* to wake up until pthread_cond_signal or pthread_cond_broadcast is called. It is not *required* to wait until either of these are called. > If there is anything > wrong about pthread_cond_wait, then it can not wake up no matter what > you did to it, including attaching to the process. There's nothing wrong with pthread_cond_wait. > So the problem is that, the threads can be waken up but they are not > scheduled on any CPU. Attaching the process can put them on CPU. The threads won't wake up because they're blocked in pthread_cond_wait and you didn't call pthread_cond_signal or pthread_cond_broadcast. So the only thing that can unblock them is a spurious wakeup. > I was trying to debug my program, but could not find anything wrong. > Those threads are put on pthread_cond_wait when the task queue is > empty. But later they never got chance to wake up. Probably because you never called pthread_cond_signal or pthread_cond_broadcast. That, or you called pthread_cond_signal or pthread_cond_broadcast while the queue was *still* empty. So the other thread woke up, checked the queue, found it empty, and went back to sleep. > I still think it is > Solaris problem. My program runs fine on a Linux machine with 8 CPU's. > That is another evidence that the logic in my program is correct. It is, of course, possible that you are correct and that it is a Solaris problem. However, more likely, there's a race condition in your program and you always win the race on Linux due to details of its scheduler. DS .