Boost logo

Boost :

Subject: Re: [boost] [thread] getting boost::thread* form boost::thread::id
From: Vicente Botet Escriba (vicente.botet_at_[hidden])
Date: 2008-11-14 18:14:55


Anthony Williams-4 wrote:
>
> "vicente.botet" <vicente.botet_at_[hidden]> writes:
>
>
>> With the current Boost.Thread interface, I don't see how I can get it
>> either from the current thread or from the thread::id. Can I?
>
> No, you can't get a pointer or reference to the boost::thread object
> for a thread from its ID. Firstly, there may not be one (e.g. the
> initial thread, or a detached thread), and secondly that would defeat
> the point of the separation. A boost::thread instance is a
> single-ownership object. In general it is not safe to access it from
> multiple threads. On the other hand, boost::thread::id values are just
> values, and can be freely copied around.
>
> Finally, if you move your thread between boost::thread objects, all
> your pointers would become invalid.
>
>

If a boost::thread instance is a single-ownership object, what about
thread::group? Is the ownership of the thread added to a group transfered to
the group? No, I don't think so.

In which cases it is not safe to access it from multiple threads?

Well even if you are right and the thread pointer was not a good idea, as
what I want is to interrupt a thread for which I have a thread::id may be
you can add a static function

    void interrupt(thread::id);

Is this function unsafe?

Vicente

-- 
View this message in context: http://www.nabble.com/-thread--getting-boost%3A%3Athread*-form-boost%3A%3Athread%3A%3Aid-tp20484926p20510022.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk