I recently looked at this std::thread reference.
For the move constructor it says:
thread( thread&& other );
Move constructor. Constructs the thread object to represent the thread of execution that was represented by other. After this call other no longer represents a thread of execution.
Also, in the example below there are these lines:
int n=0;
std::thread t3(f2, n);
std::thread t4(std::move(t3)); // t4 is now running f2(). t3 is no longer a thread
What I don't understand is what exactly happens with thread t3
and t4
? Does t4
waits until t3
finish its execution? What does it mean that t3
is no longer a thread?
std::thread
isn't a thread. It is a representation of a thread provided by an underlying operating system that you can use to manipulate the thread. This is just like a car
object isn't really a car.
move
moves the thread being represented from one std::thread
to another. After the move
, t3
is a gutless std::thread
. The std::thread
object is still there, but t3
doesn't reference any actual system thread. t4
now represents the thread previously represented by t3
, but it will not wait unless you call join
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.