Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-12-12 14:27:16


Roland Schwarz wrote:
> Peter Dimov wrote:
>
>>
>> The demand for thread ID's come from the need to _identify_ the
>> thread. In POSIX terms, every operation that takes a pthread_t uses
>> it to identify the thread on which it is supposed to operate.
>>
> A quick grep over my header file revealed:
>
> the first 5 usages are covered by boost thread
> pthread_create (pthread_t * tid, ... The ctor
> pthread_detach (pthread_t tid); The dtor
> pthread_t pthread_self (void); The default ctor
> pthread_join (pthread_t thread, ... The join function
> pthread_equal (pthread_t t1, pthread_t t2); The operator()==
>
> The remaining are (not yet) supported by boost thread
> pthread_cancel (pthread_t thread);
> pthread_setschedparam (pthread_t thread, ...
> pthread_getschedparam (pthread_t thread, ...
> pthread_kill(pthread_t thread, int sig);
>
> Do I miss some important usages of pthread_t ?
> To me it appears that the pthread_t type is simply
> a C language idiom (kind of a handle). It appears to me as not
> beeing any different than boost::thread* .
> Please explain to me where I am wrong in my assumptions.

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.

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.

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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net