In C++11, what is the point of a thread which “does not represent a thread of execution”?

Is there some other way that a “thread of execution” can be attached to that object, like thrd.start() or something similar?

// deferred start
std::thread thread;

// ...

// let's start now
thread = std::thread(functor, arg0, arg1);

std::thread is a MoveConstructible and MoveAssignable type. So that means that in code like std::thread zombie(some_functor); std::thread steal(std::move(zombie)); zombie will 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 of std::thread and operations like std::vector<std::thread>::resize.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)