tags:

views:

515

answers:

2

Is there a mechanism that I can use to tell if a pthread thread is currently running, or has exited? Is there a method for pthread_join() that is able to timeout after a specific period of time if the thread has not yet exited?

+2  A: 

If you're only targeting linux, use http://www.kernel.org/doc/man-pages/online/pages/man3/pthread%5Ftryjoin%5Fnp.3.html

If you need something for any POSIX system, you can copy the "pthread_timedjoin" implementation in http://www.opengroup.org/onlinepubs/000095399/xrat/xsh%5Fchap02.html#tag%5F03%5F02%5F08%5F21 - which uses a condition variable to signal thread termination, and pthread_cond_timedwait for the timeout.

wrang-wrang
Thanks, but it doesn't seem to be supported on my particular build.
Steven Behnke
A: 

I just ended up wrapping the thread in a C++ class and keeping a state variable around that could be checked later.

Steven Behnke