Boost logo

Boost Users :

Subject: Re: [Boost-users] [thread] boost::thread automatically detached when thread terminates?
From: Boris Schaeling (boris_at_[hidden])
Date: 2010-09-12 08:39:49


On Sun, 12 Sep 2010 06:52:49 +0200, Francesco Biscani
<bluescarni_at_[hidden]> wrote:

> [...]
>> 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?
>
> No, it will return true both times.
>
>> 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.
>> :)
>
> Maybe you can use boost::thread::timed_join() with a very low timeout
> (or even zero timeout, haven't checked if it works like that).

Thanks for your reply! Do you know whether the thread of execution is
allowed to call boost::thread::detach()? Then it could detach itself from
the boost::thread object before it terminates and
boost::thread::joinable() should work? I'm not sure though if
boost::thread is thread-safe?

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