Boost logo

Boost Users :

Subject: Re: [Boost-users] [thread] boost::thread automatically detached when thread terminates?
From: Eric J. Holtman (eric_at_[hidden])
Date: 2010-09-12 09:32:13


On 9/12/2010 7:55 AM, Boris Schaeling wrote:
>
> I want a worker thread to terminate if there is nothing to do. If
> there is something to do again and the worker thread has terminated I
> need to create a new one. Now I wonder if I can use boost::thread to
> detect whether the thread is running or not.
>

The reason boost::thread doesn't provide you with an
"is_running" function, is that it would be nearly impossible
to write it correctly.

Example:

main thread starts worker.
worker starts work.
main thread calls is_running which returns true.

now, before main thread can execute next statement, worker thread exits.

main thread tries to send more work to worker, who is gone.


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