Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-08-17 09:46:55

From: "William Kempf" <williamkempf_at_[hidden]>
> From: "Peter Dimov" <pdimov_at_[hidden]>
> >From: "William Kempf" <williamkempf_at_[hidden]>
> >>I'd prefer to
> >>leave join() as an explicit operation. The destructor shall either
> >>the thread if it is still "joinable", or do nothing if it's been joined.
> >How would you implement this? When a default-constructed thread object is
> >destroyed it doesn't know whether the thread has been already joined.
> Read the description a little closer. A "default-constructed thread
> is not joinable. Only the thread object that actually creates the thread
> joinable (and only until it calls join() once). In actuality this design
> by far easier to implement, especially on POSIX threads.

The thread object creates a thread. Within that thread, a
default-constructed thread object is created with "new thread", then passed
to someone else. The original thread object (which is joinable) performs a
join. Then that someone else deletes the default-constructed thread object.
It detaches, since it doesn't know that a join has already been performed.
Undefined behavior.

Peter Dimov
Multi Media Ltd.

Boost list run by bdawes at, gregod at, cpdaniel at, john at