Hi! Does anyone know how to check if a pthread_t is set to a valid value?
e.g. I'd like to know certain thread is running or not, but hate to add another variable to record the status of that thread, can I use pthread_t directly?
Just to be clear. My question is: What is pthread_t anyway(On linux)? Is it a pointer to a struct? An int or a long? In which header file can I find the definition of pthread_t?
pthread_t keeps a thread ID after a thread is created, with pthread_create().
Normally, you should not worry about the actual type for pthread_t, and use the API to work with a thread. But, if you are really interested, start with pthread.h and you may find how it's defined by your pthread library. In the one I use, it is an unsigned long int defined in pthreadtypes.h.
That's right, it is only an ID (think of it as an index on vector of threads, although it might not be so simple). The information about the thread is stored in OS space, which is only accessible through the OS API.