Boost logo

Boost Users :

From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2005-03-24 12:39:54


Kevin Wheatley wrote:
> Ben Hutchings wrote:
>
>>Kevin Wheatley wrote:
>>
>>>To me the most obvious thing missing is something like:
>>>
>>>void thread::join()
>>>{
>>> assert(m_joinable);
>>> int res = 0;
>>>
>>>rest of function....
>>
>>Yes, that could make the cause of errors clearer and would do a much
>>better job of detecting them than the assertion about the result of the
>>system return value. The ID or handle value in a non-joinable thread
>>object could be reused by the time of the erroneous join, so that the
>>error would not be detected by the system join function.
>
>
> as a note, if this were to happen, it would suggest that a mutex is
> needed for the duration of the thread::join() function to avoid what
> then becomes a race condition relating to the m_joinable boolean under
> the condition that multiple joins() are called by different threads at
> the same time.

Only one thread is expected to "own" another, so boost::thread does not
provide thread-safety for its own instances. It already has member
functions other than the constructor that modify state and are not
thread-safe. If a client needs shared ownership then it should be easy
enough to provide this in a wrapper, whereas if boost::thread was itself
thread-safe it would add unavoidable overhead that few clients need.

> On the subject of detatched threads, you have to create these
> youreself outside of the Boost.Threads code as far as I can see.
<snip>

No, you just have to destroy the boost::thread without joining.

Ben.


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