From owner-freebsd-threads@FreeBSD.ORG Wed Apr 4 21:36:04 2007 Return-Path: X-Original-To: freebsd-threads@freebsd.org Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id B6BC416A402 for ; Wed, 4 Apr 2007 21:36:04 +0000 (UTC) (envelope-from ed.maste@gmail.com) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.171]) by mx1.freebsd.org (Postfix) with ESMTP id 6234F13C45E for ; Wed, 4 Apr 2007 21:36:02 +0000 (UTC) (envelope-from ed.maste@gmail.com) Received: by ug-out-1314.google.com with SMTP id 71so843757ugh for ; Wed, 04 Apr 2007 14:36:02 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=CmHiibm6vlMMz8wDQahsrqXaHFJ3DShCZXUfTFzGh2MqPIxYkXLRm8ROwWK7NRiw68bshvQ08Z2KRwO17aVVqeByhmB76PUArVJjwZYomLeeux+KdCu3A6UXVq4hY1xMo4PvCx4JkBc0/qlCbEbJkE8GY5yEDPYvaTZQq80v4yY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=fm44patzP14e8AZIKnresPRF3x9YhFTeEEb+Rag+T1CytCCDpfUOMWaPPLdsESOQQB2zmlhETYXvCQfGy0SWg8mpuVbW2Ik7flSu5+2YjIP+au7MkYpb7LG9b0NUtpFNJKwNa7CLvzx7NfuPCqQXPPdR5nU6dqXUL6ozDpCBceM= Received: by 10.78.123.4 with SMTP id v4mr208812huc.1175721302556; Wed, 04 Apr 2007 14:15:02 -0700 (PDT) Received: by 10.78.188.7 with HTTP; Wed, 4 Apr 2007 14:14:57 -0700 (PDT) Message-ID: <88607eb20704041414s6bda8765u6782a0460372407f@mail.gmail.com> Date: Wed, 4 Apr 2007 17:14:57 -0400 From: "Ed Maste" To: freebsd-threads@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: [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: Wed, 04 Apr 2007 21:36:04 -0000 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;