Boost logo

Boost Users :

Subject: Re: [Boost-users] [thread] boost::thread automatically detached when thread terminates?
From: Francesco Biscani (bluescarni_at_[hidden])
Date: 2010-09-12 00:52:49


Hi Boris,

On Sun, Sep 12, 2010 at 12:04 AM, Boris Schaeling <boris_at_[hidden]> wrote:
> 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?

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).

> Boris

Cheers,

  Francesco.


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