From owner-freebsd-threads@FreeBSD.ORG Thu May 19 12:52:25 2005 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8341B16A4CF; Thu, 19 May 2005 12:52:25 +0000 (GMT) Received: from mail.ntplx.net (mail.ntplx.net [204.213.176.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0209443D91; Thu, 19 May 2005 12:52:25 +0000 (GMT) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) j4JCqN65003884; Thu, 19 May 2005 08:52:23 -0400 (EDT) Date: Thu, 19 May 2005 08:52:23 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Jens Nilsson In-Reply-To: <200505191138.j4JBcZCM040531@www.freebsd.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.ntplx.net) cc: freebsd-gnats-submit@freebsd.org cc: freebsd-threads@freebsd.org Subject: Re: threads/81258: Thread specific data is sometimes assigned to multiple keys and/or threads X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 May 2005 12:52:25 -0000 On Thu, 19 May 2005, Jens Nilsson wrote: > Thread specific data is sometimes assinged to multiple keys > and/or threads. In the attached test program two threads getting > the same tsd for the same key seems to be the most usual. > > >How-To-Repeat: > Run the attached test program a couple of times. One of the > threads will wait for input, the bug is most likely to show up if > enter is pressed in about half a second after the thread asked > for data. > > I ran into the bug some time ago while developing a bit more > complex application that involved a couple of threads all of them > with TSD and some doing RPC-calls. In that application I had the > same problem with any of the thread libs libpthread, libthr, and > libc_r. This test program only seems to be able to repeat the > problem with libpthread. Thread-specific data is destroyed when the thread exits. Your TSD is allocated using malloc() and destroyed using free(). Your test program does nothing to ensure that all threads have started running and have all created/initialized their TSD before the first thread exits. malloc() is probably reusing a prior allocation that has been free()'d. Thread exiting != Thread being joined. -- DE