I'm learning about multithreading in C++. I'm following a tutorial that gave this example for explaining the way to 'move' from one thread to another using the move semantics:
std::thread thread_1( func_1 );
std::thread thread_2 = std::move( thread_1 );
thread_1 = std::thread(func_2);
std::thread thread_3 = std::move(thread_2);
thread_1 = std::move(thread_3);
The last line thread_1 = std::move(thread_3);
was indicated as not being a proper way of doing it because(as I understood it):
'thread_1' and 'thread_3' are both existing threads which own some functions(thread_1 owns func_2 and thread_3 owns func_1) and you are supposed to manage their life-cycle with .detach() or .join();
That was the explanation given in the tutorial however that doesn't make sense to me 100%. Please help me better understand that explanation of why that line of code is not a proper way to transfer ownership between threads. Thank you!