delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/05/01/07:47:53

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
From: Michael Beach <michaelb AT ieee DOT org>
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>

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 <pthread.h>

#include <iostream>

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/

- Raw text -


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