null pthread_t
Daniel Eischen
eischen at vigrid.com
Thu Jul 10 05:58:05 PDT 2003
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
More information about the freebsd-threads
mailing list