Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Jul 2003 08:58:03 -0400 (EDT)
From:      Daniel Eischen <eischen@vigrid.com>
To:        Terry Lambert <tlambert2@mindspring.com>
Cc:        freebsd-threads@freebsd.org
Subject:   Re: null pthread_t
Message-ID:  <Pine.GSO.4.10.10307100852420.2454-100000@pcnet5.pcnet.com>
In-Reply-To: <3F0D3EF6.A9000297@mindspring.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.10.10307100852420.2454-100000>