Looking over the new threading stuff in C++11 to see how easily it maps to pthreads, I notice the curious section in the thread constructor area:
thread();
Effects: Constructs a thread object that does not represent a thread of execution.
Postcondition: get_id() == id()
Throws: Nothing.
In other words, the default constructor for a thread doesn’t actually seem to create a thread. Obviously, it creates a thread object, but how exactly is that useful if there’s no backing code for it? Is there some other way that a “thread of execution” can be attached to that object, like thrd.start() or something similar?
std::threadis a MoveConstructible and MoveAssignable type. So that means that in code likestd::thread zombie(some_functor); std::thread steal(std::move(zombie));zombiewill be left in a special, but valid, state associated with no thread of execution. The default constructor comes free in a sense since all it has to do is put the object into that exact state. It also allows arrays ofstd::threadand operations likestd::vector<std::thread>::resize.