From owner-freebsd-current Sun Apr 23 9:17:33 2000 Delivered-To: freebsd-current@freebsd.org Received: from mout0.freenet.de (mout0.freenet.de [194.97.50.131]) by hub.freebsd.org (Postfix) with ESMTP id D304A37B6BA for ; Sun, 23 Apr 2000 09:17:28 -0700 (PDT) (envelope-from netchild@leidinger.net) Received: from [62.104.201.2] (helo=mx1.freenet.de) by mout0.freenet.de with esmtp (Exim 3.14 #3) id 12jOmx-000433-00 for current@freebsd.org; Sun, 23 Apr 2000 17:59:15 +0200 Received: from [213.6.54.227] (helo=Magelan.Leidinger.net) by mx1.freenet.de with esmtp (Exim 3.14 #3) id 12jOms-0000Kn-00 for current@freebsd.org; Sun, 23 Apr 2000 17:59:11 +0200 Received: from Leidinger.net (netchild@localhost [127.0.0.1]) by Magelan.Leidinger.net (8.9.3/8.9.3) with ESMTP id RAA07061 for ; Sun, 23 Apr 2000 17:58:49 +0200 (CEST) (envelope-from netchild@Leidinger.net) Message-Id: <200004231558.RAA07061@Magelan.Leidinger.net> Date: Sun, 23 Apr 2000 17:58:45 +0200 (CEST) From: Alexander Leidinger Subject: pthread_cond_broadcast() not delivered To: current@freebsd.org MIME-Version: 1.0 Content-Type: MULTIPART/mixed; BOUNDARY="0-1804289383-956505532=:1425" Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --0-1804289383-956505532=:1425 Content-Type: TEXT/plain; charset=us-ascii Hi, (14) netchild@ttyp2% uname -a FreeBSD Magelan.Leidinger.net 5.0-CURRENT FreeBSD 5.0-CURRENT #14: Fri Apr 21 17:28:37 CEST 2000 root@:/big/usr/src/sys/compile/WORK i386 I've an application which uses pthread_cond_{wait,broadcast}() and the debug output gives me the impression that the broadcast did not get delivered anymore. I run this program only occasionally, but with 4-current (last year) it worked, and I haven't changed anything mutex-/cond-related in it since then. I've attached a short test-prog (1.7k) which shows the same behavior, compile it with "cc -D_THREAD_SAFE -pthread test.c" and run "./a.out". It should print something like: ---snip--- First: thread started, waiting for pthread_cond_broadcast(). Second: lock. Second: broadcast. Second: unlock. Second: sleep. First: got broadcast. First: join. Second: exit. ---snip--- but it prints: ---snip--- First: thread started, waiting for pthread_cond_broadcast(). Second: lock. Second: broadcast. Second: unlock. Second: sleep. Second: exit. ---snip--- and waits forever (in state "poll"). Bye, Alexander. -- Secret hacker rule #11: hackers read manuals. http://www.Leidinger.net Alexander+Home @ Leidinger.net GPG fingerprint = 7423 F3E6 3A7E B334 A9CC B10A 1F5F 130A A638 6E7E --0-1804289383-956505532=:1425 Content-Type: TEXT/plain; CHARSET=US-ASCII Content-Disposition: attachment; filename="test.c" #include #include #include #include pthread_mutex_t *main_mutex; pthread_cond_t *main_cond; void * second_thread(void *arg); int main(void) { pthread_t *thread; int thread_error, ret; setvbuf(stdout, NULL, _IONBF, BUFSIZ); setvbuf(stderr, NULL, _IONBF, BUFSIZ); /* mutex */ main_mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); if(main_mutex == NULL) { return -1; } do { ret = pthread_mutex_init(main_mutex, NULL); } while(ret == EAGAIN); if(ret != 0) return -1; /* cond */ main_cond = (pthread_cond_t *)malloc(sizeof(pthread_cond_t)); if(main_cond == NULL) { return -1; } do { ret = pthread_cond_init(main_cond, NULL); } while(ret == EAGAIN); if(ret != 0) return -1; /* lock mutex */ pthread_mutex_lock(main_mutex); /* thread */ thread = (pthread_t *)malloc(sizeof(pthread_t)); if(thread == NULL) pthread_exit(0); /* error, not enough memory */ /* create pthread */ do{ thread_error = pthread_create(thread, NULL, &second_thread, NULL); } while(thread_error == EAGAIN); fprintf(stderr, "First: thread started, waiting for pthread_cond_broadcast().\n"); /* syncronize */ pthread_cond_wait(main_cond, main_mutex); fprintf(stderr, "First: got broadcast.\n"); sleep(2); fprintf(stderr, "First: join.\n"); pthread_join(*thread, NULL); exit(0); } void * second_thread(void *arg) { /* syncronize */ fprintf(stderr, "Second: lock.\n"); pthread_mutex_lock(main_mutex); fprintf(stderr, "Second: broadcast.\n"); pthread_cond_broadcast(main_cond); fprintf(stderr, "Second: unlock.\n"); pthread_mutex_lock(main_mutex); fprintf(stderr, "Second: sleep.\n"); sleep(10); fprintf(stderr, "Second: exit.\n"); pthread_exit(0); } --0-1804289383-956505532=:1425-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message