From owner-freebsd-threads@FreeBSD.ORG Thu Apr 5 02:33:03 2007 Return-Path: X-Original-To: freebsd-threads@freebsd.org Delivered-To: freebsd-threads@freebsd.org Received: from [127.0.0.1] (localhost [127.0.0.1]) by hub.freebsd.org (Postfix) with ESMTP id 78DAE16A402; Thu, 5 Apr 2007 02:33:02 +0000 (UTC) (envelope-from davidxu@freebsd.org) Message-ID: <46145FF4.9080703@freebsd.org> Date: Thu, 05 Apr 2007 10:33:24 +0800 From: David Xu User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.13) Gecko/20061204 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Ed Maste References: <88607eb20704041414s6bda8765u6782a0460372407f@mail.gmail.com> In-Reply-To: <88607eb20704041414s6bda8765u6782a0460372407f@mail.gmail.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-threads@freebsd.org Subject: Re: [PATCH] libthr - pthread_set_name_np crash X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Apr 2007 02:33:03 -0000 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