From owner-freebsd-threads@FreeBSD.ORG Wed Jun 4 10:12:40 2003 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 0A08737B401 for ; Wed, 4 Jun 2003 10:12:40 -0700 (PDT) Received: from mail.chesapeake.net (chesapeake.net [208.142.252.6]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3E6C543F3F for ; Wed, 4 Jun 2003 10:12:39 -0700 (PDT) (envelope-from jroberson@chesapeake.net) Received: from localhost (jroberson@localhost) by mail.chesapeake.net (8.11.6/8.11.6) with ESMTP id h54HCY753778; Wed, 4 Jun 2003 13:12:34 -0400 (EDT) (envelope-from jroberson@chesapeake.net) Date: Wed, 4 Jun 2003 13:12:34 -0400 (EDT) From: Jeff Roberson To: Kern Sibbald In-Reply-To: <1054745115.13630.517.camel@rufus> Message-ID: <20030604130858.M69975-100000@mail.chesapeake.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: Daniel Eischen cc: freebsd-threads@freebsd.org Subject: Re: FreeBSD pthread_equal "bug" X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jun 2003 17:12:40 -0000 On 4 Jun 2003, Kern Sibbald wrote: > On Wed, 2003-06-04 at 17:30, Daniel Eischen wrote: > > On 4 Jun 2003, Kern Sibbald wrote: > > > Hello, > > > > > > I've run into what I consider a bug in the FreeBSD > > > implementation of pthreads and pthread_equal() in > > > particular. Basically, pthread_equal() will return > > > true even if it is not the same thread. This can occur > > > when one thread dies and another one starts. The second > > > thread then takes on the exact identity of the the > > > first thread, and pthread_equal() returns true for a > > > case where it is a different thread. You may argue > > > that the first thread is dead so its thread id is no > > > longer valid. True, but think about how Unix would > > > work if every process started up with the process > > > id of the last process to exit. > > > > Process id's can wrap around so it can eventually happen. > > Yes, true. However, on Solaris and Linux, it takes a long time, > for the pthread_id to wrap around, and on FreeBSD it happens in > microseconds. > > > > > This is a bug in the application; the implementation is allowed > > to reuse thread id's and there are enough interfaces for an > > application to tell when a thread terminates (pthread_join). > > I'm not sure what the POSIX specification says, > if I were programming it, I would not be content > with the FreeBSD current implementation especially > considering that both Solaris and Linux do it "correctly". Would you rather your application failed immediately, or in a subtle, unexpected way after many hours/weeks/months of run time? Dan says the standard allows for immediate reuse. If that is correct, then Solaris, linux, and FreeBSD all do it correctly for the only definition of correctly that matters. Simply adding an ID is problematic because the ids will wrap. Without using some deterministic notification you can't be sure that it isn't an expired thread. > > > Perhaps our use of thread id's could be changes so that they > > were cached at the end of the free thread list, but cacheing > > them at the front seems to highlight bad applications, so > > that's a bonus ;-) > > This bug does not highlight bad applications because most > programmers will reasonably expect that pthread_equal() will > not be the same for two different threads. It took me > a long time to find this problem because I just could not > imagine that pthread_equal() was not "working". > This problem is extremely subtle and is likely to cause > unsuspecting applications long months of bizarre > behavior. > > Fix it or not, that is your choice. Now that I know > that you don't handle it as I would suspect I can code > around it. > > _______________________________________________ > freebsd-threads@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-threads > To unsubscribe, send any mail to "freebsd-threads-unsubscribe@freebsd.org" >