Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Message-ID: <3B290FE5.22678B61@trex.rtpnc.epa.gov> Date: Thu, 14 Jun 2001 15:26:29 -0400 From: Greg Smith X-Mailer: Mozilla 4.74 [en] (WinNT; U) X-Accept-Language: en MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: hang in pthread_cond_signal Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I am using the cygwin-src snapshot from June 10. Seems pthread_cond_signal can hang while another thread is waiting on the condition AND a pthread_cond_signal has been previously issued when no one was waiting on the condition. Below is a testcase that illustrates the problem: Thanks, Greg GSmith AT GREG ~ $ cat ptbarf.c #include #include #include pthread_cond_t cond; pthread_mutex_t lock; void *t1(); int main() { pthread_t tid; void *ret; if (pthread_cond_init(&cond, NULL)) { printf("init failed for cond: %s\n", errno); return; } if (pthread_mutex_init(&lock, NULL)) { printf("init failed for lock: %s\n", errno); return; } if (pthread_mutex_lock(&lock)) { printf("main lock failed: %s\n", errno); return; } printf("main has lock\n"); #ifdef DEBUG // issue spurious cond_signal to cause the problem if (pthread_cond_signal(&cond)) { printf("main signal failed: %s\n", errno); return; } #endif if (pthread_create(&tid, NULL, t1, NULL)) { printf("create for t1 failed: %s\n", errno); return; } printf("main waiting\n"); if (pthread_cond_wait(&cond, &lock)) { printf("main wait failed: %s\n", errno); return; } if (pthread_mutex_unlock(&lock)) { printf("main unlock failed: %s\n", errno); return; } printf("main released lock\n"); if (pthread_join(tid, &ret)) { printf("join for t1 failed: %s\n", errno); return; } printf ("main terminating\n"); } void *t1() { sleep(5); printf("t1 getting lock\n"); if (pthread_mutex_lock(&lock)) { printf("t1 lock failed: %s\n", errno); return; } printf("t1 signalling cond\n"); if (pthread_cond_signal(&cond)) { printf("t1 signal failed: %s\n", errno); return; } printf("t1 releasing lock\n"); if (pthread_mutex_unlock(&lock)) { printf("t1 unlock failed: %s\n", errno); return; } printf ("t1 terminating\n"); } GSmith AT GREG ~ $ gcc -o ptbarf ptbarf.c GSmith AT GREG ~ $ ./ptbarf main has lock main waiting t1 getting lock t1 signalling cond t1 releasing lock main released lock t1 terminating main terminating GSmith AT GREG ~ $ gcc -DDEBUG -o ptbarf ptbarf.c GSmith AT GREG ~ $ ./ptbarf main has lock main waiting t1 getting lock t1 signalling cond -- Want to unsubscribe from this list? Check out: http://cygwin.com/ml/#unsubscribe-simple