Boost logo

Boost Users :

From: Martin Pasdzierny (martin_at_[hidden])
Date: 2005-01-04 05:28:37

Roland Schwarz wrote:
> Peter Dimov wrote:
>> pthread_self gives you a full pthread_t, which you can use as input to
>> pthread_join, pthread_cancel, pthread_setschedparam; you can also give
>> this pthread_t to another thread and it remains valid.
> Is this even true after having detached a thread?
> Is it still valid to join a thread by means of a thread id that has been
> obtained with pthread_self after the
> thread has been detached?

man pthread_detach says:
pthread_detach put the thread th in the detached state. This guarantees that the memory resources consumed by th will be freed immediately
when th terminates. However, this prevents other threads from synchronizing on the termination of th using pthread_join.

>> boost::thread::thread() doesn't give you a boost::thread*, the
>> boost::thread surrogate it creates is valid only within the current
>> thread, and it can only be compared to another boost::thread.
> As long as the boost::thread has not been "delete"ed (the equivalent of
> detach) you are free to use the boost::thread* from
> any other thread you like.
>> pthread_self "always works"; it does not depend on some user not
>> destroying a boost::thread object. A boost::thread* in thread-specific
>> storage does not have this property.
> This is indeed an interesting question I would like to know the answer.
> Again: does "alqays" imply "even after having been detached"?
> I suspect, that boost::thread* behaves almost identical to pthread_t in
> a semantical sense.

Do You mean

   boost::thread::thread() == *th

with th pointing to a boost::thread is *always* a semantically meaningful expression including the case th pointing to the current thread (but th != &boost::thread::thread()) ?


Martin Pasdzierny, <martin_at_[hidden]>

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at