Date: Thu, 05 Apr 2007 10:33:24 +0800 From: David Xu <davidxu@freebsd.org> To: Ed Maste <ed.maste@gmail.com> Cc: freebsd-threads@freebsd.org Subject: Re: [PATCH] libthr - pthread_set_name_np crash Message-ID: <46145FF4.9080703@freebsd.org> In-Reply-To: <88607eb20704041414s6bda8765u6782a0460372407f@mail.gmail.com> References: <88607eb20704041414s6bda8765u6782a0460372407f@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Ed Maste wrote: > 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; Yes, this patch is correct, please commit it. Regards, David Xu
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?46145FF4.9080703>