From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28402 invoked by alias); 18 Nov 2004 03:45:13 -0000 Mailing-List: contact pthreads-win32-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sources.redhat.com Received: (qmail 28329 invoked from network); 18 Nov 2004 03:45:03 -0000 Received: from unknown (HELO serge.ecosm.com) (202.37.218.3) by sourceware.org with SMTP; 18 Nov 2004 03:45:03 -0000 Received: (qmail 31736 invoked by uid 503); 18 Nov 2004 03:45:01 -0000 Received: from 203-79-66-6.adsl-wns.paradise.net.nz (HELO ?192.168.2.20?) (203.79.66.6) by serge.ecosm.com with SMTP; 18 Nov 2004 03:45:01 -0000 Message-ID: <419C1B3E.1020902@ecosm.com> Date: Thu, 18 Nov 2004 03:45:00 -0000 From: Will Bryant Organization: eCOSM Limited User-Agent: Mozilla Thunderbird 0.9 (Windows/20041103) MIME-Version: 1.0 To: pthreads-win32@sources.redhat.com Subject: Re: Possible violation of synchronization in pthread_cond_timedwait() References: <20041118033814.8BE764392B@smtp.263.net> In-Reply-To: <20041118033814.8BE764392B@smtp.263.net> X-Enigmail-Version: 0.89.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: 7bit X-SW-Source: 2004/txt/msg00152.txt.bz2 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.