Yuval Ronen wrote:
A default-constructed thread is documented as being non-joinable:
Ok, I can't join it. So what can I do with it?
Not a whole heck of a lot aside from comparing it to other threads.
This brings me some thoughts. The thread class is non-copyable (which is fine by me) and also it has an operator==. I think these two things contradict each other. When defining an equal operator, we are actually defining semantics for copying: copying an object will result in a second object that will be equal, in terms of operator==, to the first object. Defining an equal operator means that objects can be equal, or in other works, they are a copies of the same value! <snip>
As I see it, the problem is that thread combines the functions of thread ID and thread handle. Joinable and non-joinable thread objects are two very different types and the type system should reflect that. I think that thread should be separated into two classes: class thread_id // Exposition only { public: // construct/copy/destruct thread_id(); thread_id(const thread_id &); ~thread_id(); // modifier thread_id & operator=(const thread_id &); // comparison bool operator==(const thread_id &) const; bool operator!=(const thread_id &) const; }; class thread : private boost::noncopyable // Exposition only { public: // construct/copy/destruct explicit thread(const boost::function0<void>&); ~thread(); // modifier void join(); // static static void sleep(const xtime&); static void yield(); }; Then every thread object would be joinable and every thread_id would be copiable. Ben.