|
Boost Users : |
Subject: Re: [Boost-users] [thread] boost::thread automatically detached when thread terminates?
From: Boris Schaeling (boris_at_[hidden])
Date: 2010-09-11 18:04:08
On Sat, 11 Sep 2010 23:22:12 +0200, Lars Viklund <zao_at_[hidden]> wrote:
> On Sat, Sep 11, 2010 at 11:00:56PM +0200, Boris Schaeling wrote:
>> Is a boost::thread object automatically detached when a thread
>> terminates?
>>
>> I read in the Boost.Thread 1.44 documentation: "If the thread of
>> execution represented by the boost::thread object has already completed,
>> or the boost::thread object represents Not-a-Thread, then join() returns
>> immediately."
>>
>> Is it really required to call join() or timed_join()? Or can I also call
>> joinable() which would return false then?
>
> The four ways of cleaning up properly after a thread with Boost.Thread
> are:
Sorry, I wasn't clear then. I'm trying to find out how I can easily tell
whether a thread of execution has terminated:
boost::thread t(...);
// thread of execution runs
bool running = t.joinable();
// thread of execution terminates (automatically)
bool still_running = t.joinable();
Does joinable() return true in the first case and false in the second? The
documentation says that in the second case join() returns immediately.
However I don't want to call join() because it would block in the first
case. I would need to know in advance whether the thread of execution has
terminated or not - this is exactly what I'd like boost::thread to tell
me. :)
Boris
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