Date: Wed, 4 Apr 2007 17:14:57 -0400 From: "Ed Maste" <ed.maste@gmail.com> To: freebsd-threads@freebsd.org Subject: [PATCH] libthr - pthread_set_name_np crash Message-ID: <88607eb20704041414s6bda8765u6782a0460372407f@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
It seems there is a bug in pthread_set_name_np for the thread != curthread case. That is, pthread_set_name_np called from outside of the thread being named, as in the following example: pthread_create(&pt, 0, t_spin, (void *)1); [...] pthread_set_name_np(pt, "t1"); The bug is a race condition that leads to thread->locklevel being incorrect. Based on the other cases of locking a not-curthread thread, I think the patch below is the fix. Can a libthr expert comment? Thanks, Ed Index: thr_info.c =================================================================== RCS file: /usr/cvs/src/lib/libthr/thread/thr_info.c,v retrieving revision 1.9 diff -u -r1.9 thr_info.c --- thr_info.c 12 Jan 2007 07:26:20 -0000 1.9 +++ thr_info.c 23 Mar 2007 14:56:13 -0000 @@ -52,12 +52,12 @@ ret = errno; } else { if (_thr_ref_add(curthread, thread, 0) == 0) { - THR_LOCK(thread); + THR_THREAD_LOCK(curthread, thread); if (thread->state != PS_DEAD) { if (thr_set_name(thread->tid, name)) ret = errno; } - THR_UNLOCK(thread); + THR_THREAD_UNLOCK(curthread, thread); _thr_ref_delete(curthread, thread); } else { ret = ESRCH;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?88607eb20704041414s6bda8765u6782a0460372407f>