From: Howard Hinnant (hinnant_at_[hidden])
Date: 2008-05-28 13:22:09
On May 28, 2008, at 11:09 AM, Stefan Seefeld wrote:
> Anthony Williams wrote:
>> "vicente.botet" <vicente.botet_at_[hidden]> writes:
>>> just a question that could clarify my thoughts, can a non joinable
>>> thread be
>> No, because you no longer have a handle with which to interrupt it.
>> I have thought about providing an "interrupt handle" which you can
>> obtain either from a boost::thread object, or by calling
>> boost::this_thread::get_interrupt_handle() or similar, in which
>> case a
>> detached thread would be interruptible.
> But why do you invalidate the thread object after a call to detach ?
> is it impossible to refer to a detached thread ? (And, for that
> why can't a default-constructed thread not simply refer to the 'main'
> thread ?)
> Why do we have unreferrable (sp?) threads of execution ?
Because when a thread is detached, you can not reliably query it for
things such as it's id. You don't know whether the detached thread is
still running or not. Perhaps it has terminated, and another thread
has been launched and was assigned the same id.
If you need to refer to a thread (via a std::thread), just don't
detach it. If you want, you can arrange other communication
mechanisms with a thread (such as a condition_variable), and then you
can detach it and still communicate with it via the cv.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk