Boost logo

Boost Users :

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


Kevin Wheatley wrote:
> Peter Dimov wrote:
>
>>Kevin Wheatley reports that the assert( res == WAIT_OBJECT_0 ) is failing
>>for him on Windows. Printing res (WAIT_FAILED) or GetLastError() ("invalid
>>handle" would be my bet) won't give us much information as to whether the
>>assert is failing due to double thread::join, thread::join on a
>>default-constructed thread, or an internal error in Boost.Threads.
>
>
> 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.

<snip>
> but then does this mean there should be a
>
> bool thread::isJoinable() const { return m_joinable; }
>
> function too?
<snip>

This seems somewhat reasonable. However, currently there are two
significantly different reasons for thread objects to be non-joinable -
either the thread is default-constructed and is just an ID holder or the
thread has already been joined. These should be distinguishable. I'm
convinced that there should be entirely separate types for thread IDs
and thread starter/joiner objects and don't understand why they were
given the same type.

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