null pthread_t

Daniel Eischen eischen at vigrid.com
Wed Jul 9 19:47:13 PDT 2003


On Wed, 9 Jul 2003, Brooks Davis wrote:

> I've got some Linux pthread code that goes something like this that I'm
> porting to FreeBSD:
> 
> ------
> pthread_t tid;
> 
> tid = -1;
> 
> /* Do stuff including maybe creating a thread. */
> 
> if (tid != -1) {
> 	pthread_cancel(tid);
> 	pthread_join(tid, NULL);
> }
> ------
> 
> 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.

The code in question shouldn't be doing that.  If it needs to know
whether a thread id is valid, it should have a separate flag for
it (tid_valid) or possibly use pthread_kill(tid, 0) and checking
the return value (sending signal 0 to a thread is akin to sending
a process signal 0; the signal isn't delivered but the process id
is checked for validity).

-- 
Dan Eischen



More information about the freebsd-threads mailing list