Subj : Re: [RFC] Boost.Threads on its way to C++0x To : comp.programming.threads From : Ben Hutchings Date : Sat Apr 30 2005 05:14 am Howard Hinnant wrote: > In article , > Ben Hutchings wrote: > >> Peter Dimov wrote: >> > Ben Hutchings wrote: >> >> >> >> The two thread constructors are a crime against type-safety. Thread >> >> starter/joiners and identifiers should be separate types. >> > >> > Why should starters/joiners be types? Why not functions >> > returning/taking an id? >> >> I wouldn't argue that starting and joining need to be combined in a >> single class. However thread joinability is a resource which had >> better not be leaked. Some kind of resource management is needed and >> the non-default constructor of boost::thread provides RAII. > > The boost::thread dtor takes this into account. If the local > boost::thread object destructs before an explicit join, the dtor > detaches the referenced thread. I.e. the boost::thread model assumes > that the programmer will sometimes not want to join with the thread, > allows for it, and makes sure no damage is done. I understand this, and I think it's fine as far as it goes. I don't know why you're telling me since it doesn't seem to contradict anything I've said. The problem I have is that while the non-default constructor of boost::thread produces an object that's both an identifier and a joiner, the default constructor produces an object that's just an identifier. These are quite different kinds of object, yet they have the same type and there isn't even a member function that can distinguish them! The two different roles should be separated into two types, say thread and thread_id. thread would then have a member function that returns the corresponding thread_id. -- Ben Hutchings Time is nature's way of making sure that everything doesn't happen at once. .