This is the mail archive of the pthreads-win32@sources.redhat.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Possible violation of synchronization in pthread_cond_timedwait()


qybupt@263.net wrote:

>I run it in the VC6.0 and found that in CAudioMessageQueue::queuePop() the thread sometimes 
>excuted the "msg = *m_head;" when m_head was equal to NULL! The pthread_cond_timedwait's normal 
>return indicated that the condition waited had been signaled and the queue had at least one 
>message, but there was none in it. 
>  
>
This is called a 'spurious wakeup'. They happen with all POSIX condition
variables implementations (in fact, all CVs I've ever seen except for
Java's, which prevent them by imposing extra constraints). You need to
loop and re-check your condition (and if necessary wait again) - that's
why they're called condition variables.

See volume 2 of Stevens' "Unix Network Programming", or read the manual
pages for the pthreads CV calls if you can't get a copy of that.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]