This is the mail archive of the
mailing list for the pthreas-win32 project.
Re: Possible violation of synchronization in pthread_cond_timedwait()
- From: Will Bryant <will dot bryant at ecosm dot com>
- To: pthreads-win32 at sources dot redhat dot com
- Date: Thu, 18 Nov 2004 16:47:10 +1300
- Subject: Re: Possible violation of synchronization in pthread_cond_timedwait()
- Organization: eCOSM Limited
- References: <20041118033814.8BE764392B@smtp.263.net>
>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.