delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/05/01/08:24:22

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
content-class: urn:content-classes:message
MIME-Version: 1.0
Subject: RE: 1.1.3 and upwards: apparent bug with pthread_cond_wait() and/or signal()
X-MimeOLE: Produced By Microsoft Exchange V6.0.5762.3
Date: Wed, 1 May 2002 22:22:23 +1000
Message-ID: <FC169E059D1A0442A04C40F86D9BA7600C5F6D@itdomain003.itdomain.net.au>
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
From: "Robert Collins" <robert DOT collins AT itdomain DOT com DOT au>
To: "Michael Beach" <michaelb AT ieee DOT org>, <cygwin AT cygwin DOT com>
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id g41COLq19280


> -----Original Message-----
> From: Michael Beach [mailto:michaelb AT ieee DOT org] 
> Sent: Wednesday, May 01, 2002 9:44 PM
> To: cygwin AT cygwin DOT com
> Subject: 1.1.3 and upwards: apparent bug with 
> pthread_cond_wait() and/or signal()
> 
> 
> Hi all, I've just been wrestling with some code I've been 
> writing, trying to 
> get pthreads condition variables to work under Cygwin on 
> Windows 2000. I've 
> tried DLL versions 1.1.3 and the 20020409 snapshot, and 
> neither are working 
> for me, so I'm assuming that no versions in between will work 
> either...

Between 1.1.3 and 1.3.0 a huge change occurred in the pthreads code
base, so this assumption is not safe. (It's not necessarily wrong
either.) I'd definitely be using 1.3.10 though.
 
> #include <pthread.h>
> #include <iostream>

The cygwin c++ libgcc, stdlibc++ and gcc are not built with thread
support, so C++ and threads may not work well together. C should work
fine, and if anyone convinces Chris to release a thread-enabled gcc, C++
should get better.
 
> 
> 
> int main(int argc, char *argv[])
> 
> {
> 
>     CondVarTestData td;
> 
>     pthread_mutex_init(&td.m, 0);
> 
>     pthread_cond_init(&td.cv, 0);
> 
>     td.state = CondVarTestData::START;
> 
>     pthread_t th;
> 
>     pthread_create(&th, 0, condVarTestThreadEntry, &td);
> 
>     {
> 
> 	pthread_mutex_lock(&td.m);

you should lock this before starting your thread. It's a potential race.
And due to cygwin's implementation, it *is* racing, and your other
thread is entering the mutex and signalling before you enter the mutex
and wait. That early signal with no waiters gets lost (as it should).

You should also _always_ test for the return value when using pthreads
calls. They don't throw exceptions and they don't set errno, so the only
way you can tell an error has occurred is to record the return value. 

Rib

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019