Re: pthread_t

On 2007-01-31, Loic Domaigne <loic-dev@xxxxxxx> wrote:
Hi Chris,

For some reason I clear a pthread_t using memset(). I can't remember why I
do it this way!?! I have a feeling that it was necessary for early 2.4
kernels? Or perhaps I'm just wrong.

On Linux, pthread_t has been always of type unsigned lont int.

With LinuxThreads (the default Pthreads library on 2.4 kernel), the
pthread_t was in fact related to an index of an internal table. With
NPTL, the pthread_t holds the memory address of a structure that
describes the thread properties.

Anyway, since pthread_t is defined as an unsigned long int
in /usr/include/bits/pthreadtypes.h:typedef unsigned long int pthread_t;
wouldn't setting it to simply 0 do the trick?

I use only the 2.6+ kernel, so I'm not concerned with backward compat.

If your program leaves on day the realm of Linux, then you will find
the /memset()/ solution to be portable, whereas something like:

pthread_t tid;
tid = (pthread_t) 0;

may not necessarily compile on other Unix derivatives.

Yeah, do this instead:

pthread_t tid={0};

It will compile - it's standard c.

but if it needs to be nulled at some other time use memset(),


Relevant Pages