June 2018
Intermediate to advanced
348 pages
8h 45m
English
From the examples discussed so far in this chapter, you might have noticed that the function that launches the thread has to wait for the thread to complete its execution using the join() function, otherwise it will call detach() with a cost of the program losing control over the thread. In modern C++, many standard types are movable, but cannot be copied; std::thread is one of them. This means that the ownership of a thread's execution can be moved between std::thread instances with the help of move semantics.
There are many situations where we want to move the ownership to another thread, for example, if we want the thread to run in the background without waiting for it on the function that created the thread. This ...