From owner-freebsd-threads@FreeBSD.ORG Thu Jul 10 05:58:04 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 EF8E037B401 for ; Thu, 10 Jul 2003 05:58:04 -0700 (PDT) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id 551A943F3F for ; Thu, 10 Jul 2003 05:58:04 -0700 (PDT) (envelope-from eischen@vigrid.com) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mail.pcnet.com (8.12.8/8.12.1) with ESMTP id h6ACw3AI005955; Thu, 10 Jul 2003 08:58:03 -0400 (EDT) Date: Thu, 10 Jul 2003 08:58:03 -0400 (EDT) From: Daniel Eischen X-Sender: eischen@pcnet5.pcnet.com To: Terry Lambert In-Reply-To: <3F0D3EF6.A9000297@mindspring.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: Brooks Davis cc: freebsd-threads@freebsd.org Subject: Re: null pthread_t X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: deischen@freebsd.org List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jul 2003 12:58:05 -0000 On Thu, 10 Jul 2003, Terry Lambert wrote: > Brooks Davis wrote: > > Since FreeBSD uses pointers instead of integers for pthread_t's, this > > generates warnings which go away if you replace -1 with NULL, but > > it seems like that is likely to do bad things on linux. Is there a > > portable NULL-equivalent pthread_t? I'm not seeing anything jump out at > > me in the headers. > > pthread_t PTHREAD_NULL; /* global NULL equivalent */ > > pthread_t ptr; > > > ... > > if( ptr == PTHREAD_NULL) > > Basically, the type will be a BSS zero'ed global "NULL" in both > compilation environments, and the comparison will "just work" > because the type will be right. This doesn't work where pthread_t's are integer id's (perhaps used as indices into a lookup table to find the real pointer). An index of 0 may be a valid thread id (which is why I assume it was set to -1 in Linux). Unless you are advocating defining PTHREAD_NULL differently depending on the threads implementation... But the code should be rewritten to use a different method of validating the thread (use a flag, or encapsulate it in an application defined type along with a flag). -- Dan Eischen