Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , 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-Type: text/plain; charset="iso-8859-15" From: Michael Beach To: cygwin AT cygwin DOT com Subject: 1.1.3 and upwards: apparent bug with pthread_cond_wait() and/or signal() Date: Wed, 1 May 2002 21:44:11 +1000 MIME-Version: 1.0 Message-Id: <0205012144110K.17400@gilgamesh> Content-Transfer-Encoding: 8bit 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... When I build an run my test program (attached below) I get the following results... $ ./a.exe -- test thread has signal()ed -- test thread about to wait()... -- main thread wakes! -- main thread about to signal() -- main thread waiting for exit... and the program hangs. Presumably the test thread does not wake. On the other hand, when I compile the same test program on SuSE Linux 7.2 (gcc 2.95.3, glibc 2.2.2) I get what I consider to be correct results... michaelb AT gilgamesh:~ > ./a.out -- test thread has signal()ed -- test thread about to wait()... -- main thread wakes! -- main thread about to signal() -- main thread waiting for exit... -- test thread wakes! -- test thread about to exit... %% PASSED I've done a lot of staring at my test program, and can't see any problem with it (though I'm willing to be proved wrong in this, I can stand the shame!), so I'm thinking that this is a Cygwin bug. Regards M.Beach /* * foo.cpp */ #include #include using namespace std; void *condVarTestThreadEntry(void *arg); struct CondVarTestData { pthread_mutex_t m; pthread_cond_t cv; enum { START, NEW_THREAD_RUNNING, NEW_THREAD_ACKNOWLEDGED } state; }; 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); while (td.state != CondVarTestData::NEW_THREAD_RUNNING) { pthread_cond_wait(&td.cv, &td.m); clog << "-- main thread wakes!" << endl; } td.state = CondVarTestData::NEW_THREAD_ACKNOWLEDGED; clog << "-- main thread about to signal()" << endl; pthread_cond_signal(&td.cv); pthread_mutex_unlock(&td.m); } clog << "-- main thread waiting for exit..." << endl; pthread_join(th, 0); cout << "%% PASSED" << endl; return 0; } void *condVarTestThreadEntry(void *arg) { CondVarTestData *td = (CondVarTestData *)arg; pthread_mutex_lock(&td->m); td->state = CondVarTestData::NEW_THREAD_RUNNING; pthread_cond_signal(&td->cv); clog << "-- test thread has signal()ed" << endl; while (td->state != CondVarTestData::NEW_THREAD_ACKNOWLEDGED) { clog << "-- test thread about to wait()..." << endl; pthread_cond_wait(&td->cv, &td->m); clog << "-- test thread wakes!" << endl; } pthread_mutex_unlock(&td->m); clog << "-- test thread about to exit..." << endl; return 0; } 0d03a9 AT INTHN -- 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/