Date: Thu, 15 Jan 1998 11:09:57 -0600 (CST) From: Mark Tinguely <tinguely@plains.NoDak.edu> To: freebsd-hackers@FreeBSD.ORG, jacques@oskar.nanoteq.co.za Subject: Re: Pthreads question Message-ID: <199801151709.LAA17795@plains.NoDak.edu>
next in thread | raw e-mail | index | archive | help
This semester, a NDSU CS class started to use pthreads. From the last couple days worth of seeing them struggle, it is MHO that libc_r is buggy and old. you may want to get Pthreads 1.8.3 from: http://www.humanfactor.com/pthreads/ it took minor changes to port your example to pthread 1.8.3 (below), but the output was: $ ./xxxpthread 0 [.] [.] $ ./xxxpthread 1 [.] [.] *** xxxpthread.c.orig Thu Jan 15 11:04:01 1998 --- xxxpthread.c Thu Jan 15 11:00:05 1998 *************** *** 11,16 **** --- 11,20 ---- pthread_mutex_t mu; int fin=0; + extern pthread_attr_t pthread_attr_default; + pthread_mutexattr_t pthread_mutexattr_default = { MUTEX_TYPE_FAST, 0 }; + pthread_condattr_t pthread_condattr_default = { MUTEX_TYPE_FAST, 0 }; + void fg(void) { struct timespec ts; *************** *** 46,63 **** if (argc<2) exit(1); ! pthread_mutex_init(&mu,pthread_mutexattr_default); ! pthread_cond_init(&co,pthread_condattr_default); ! pthread_create(&th,pthread_attr_default,(void *)bg,NULL); if (argv[1][0]=='1') ! pthread_create(&th2,pthread_attr_default,(void *)fg,NULL); else fg(); pthread_join(th,NULL); ! pthread_detach(&th); pthread_cond_destroy(&co); pthread_mutex_destroy(&mu); --- 50,67 ---- if (argc<2) exit(1); ! pthread_mutex_init(&mu,&pthread_mutexattr_default); ! pthread_cond_init(&co,&pthread_condattr_default); ! pthread_create(&th,&pthread_attr_default,(void *)bg,NULL); if (argv[1][0]=='1') ! pthread_create(&th2,&pthread_attr_default,(void *)fg,NULL); else fg(); pthread_join(th,NULL); ! pthread_detach(th); pthread_cond_destroy(&co); pthread_mutex_destroy(&mu);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199801151709.LAA17795>