mysterious hang in pthread_create

Kostik Belousov kostikbel at gmail.com
Fri Aug 29 14:34:10 UTC 2008


On Fri, Aug 29, 2008 at 12:41:58AM +0300, Andriy Gapon wrote:
> on 28/08/2008 23:52 Andriy Gapon said the following:
> >So can all this be a result of an exception thrown before threads are 
> >initialized?
> 
> This seems to be it.
> I can reproduce the issue with the following small C++ program:
> 
> /*********************************************/
> #include <pthread.h>
> 
> 
> static void * thrfunc(void * arg)
> {
>     return NULL;
> }
> 
> int main(void)
> {
>     pthread_t thr;
> 
>     try {
>         throw int(1);
>     }
>     catch (...) {}
> 
>     pthread_create(&thr, NULL, thrfunc, NULL);
> 
>     return 0;
> }
> /*********************************************/
> 
> 
> $ uname -a
> ... FreeBSD 7.0-STABLE #9: Sun Jul  6 17:13:22 EEST 2008 ... i386
> 
> -- 
> Andriy Gapon

I am wondering why did you not fixed it youself with all this information.
Anyway, patch below seems to work for me. David may have an opinion on
the change.

diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c
index f96bba9..785d610 100644
--- a/lib/libthr/thread/thr_init.c
+++ b/lib/libthr/thread/thr_init.c
@@ -355,6 +355,9 @@ _libpthread_init(struct pthread *curthread)
 		if (_thread_event_mask & TD_CREATE)
 			_thr_report_creation(curthread, curthread);
 	}
+
+	if (_thr_isthreaded() == 0)
+		_thr_setthreaded(1);
 }
 
 /*
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-threads/attachments/20080829/d775367c/attachment.pgp


More information about the freebsd-threads mailing list