Boost logo

Boost Users :

Subject: Re: [Boost-users] Questions about packaged_task , Promise and serialization of a class object and event handling
From: Igor R (boost.lists_at_[hidden])
Date: 2012-04-16 06:13:30


> does a thread of execution always have an id ?
> i mean does a threads id gets deleted when we make a thread detached ?

It's not that thread id "gets deleted", but a detached thread object
releases its internal thread info and thus it cannot return you thread
id or any other thread-related info.

> im asking this because , if i detach a thread , and thus there is no valid
> boost::thread object available , how can i access a thread Id using boost::this_thread::get_id() ?

This is because the facilities, which reside inside this_thread
namespace, are available to you even if there's no thread object
associated with this thread. You can even launch a thread using
non-boost api (like _beginthread), and still be able to use
this_thread functions (except for interruption).

> the detached thread is not a boost::thread object any more right? then whats the point of comparing the id of this_thread ?! will it make sense at all ?

Yes, if you took thread.id(), stored it somewhere, called
thread.detach(), you can later compare this id against
this_thread::get_id().


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