As I see it, the problem is that thread combines the functions of thread ID and thread handle.
This is not a problem. I was talking purly about the thread interface, and this is implementation. Also I can add that this implementation is not limiting the interface in any way (remember the DuplicateHandle() from the first message), so no problem.
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.
According to your proposition, if I understood correctly, there is no no-parameters constructor to thread, and all threads are joinable. This is exactly what I was preaching to in my suggestion, so there is no argument between us there. The difference is that you offer to add a new thread_id class which I think is of no use at all. You need to add some kind of connection between class thread and class thread_id, something like: thread_id thread::get_thread_id(); // thread method and then you'll go around and compare thread_ids. What for? If we agree that threads cannot be copied, it means that each thread can be represented by only one thread object. Pass the address of thread objects and compare them, if you really want to. It'll give you the exact same result. Yuval