For example
boost::thread th = boost::thread(a_lengthy_function);
th.detach();
th = boost::thread(another_function);
Will first thread be canceled or affected by second thread?
For example
boost::thread th = boost::thread(a_lengthy_function);
th.detach();
th = boost::thread(another_function);
Will first thread be canceled or affected by second thread?
from boost doc:
A thread can be detached by explicitly invoking the detach() member function on the boost::thread object. In this case, the boost::thread object ceases to represent the now-detached thread, and instead represents Not-a-Thread.
thread() noexcept;Effects:Constructs a boost::thread instance that refers to Not-a-Thread
so a detached thread is the same thing as a default constructed thread. So, yes, you can safely move-assign to a default constructed thread, and the answer to your second question is no, the two threads are totally unrelated.
FYI, the same applies to std::thread as well ...
This shouldn't matter at all.
As mentioned by André Caron:
The boost::thread object's lifetime and the native thread's lifetime are unrelated. The boost::thread object can go out of scope at any time.
from What’s the best way to delete boost::thread object right after its work is complete?