Date: Sun, 23 Apr 2000 17:58:45 +0200 (CEST) From: Alexander Leidinger <Alexander@Leidinger.net> To: current@freebsd.org Subject: pthread_cond_broadcast() not delivered Message-ID: <200004231558.RAA07061@Magelan.Leidinger.net>
next in thread | raw e-mail | index | archive | help
--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 <errno.h> #include <stdio.h> #include <pthread.h> #include <unistd.h> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200004231558.RAA07061>