Learning C++ multi-threading.
In my example, thread helper1
and helper2
have finished executing before the main
thread finished. Howev
Based on the reference, underlying thread must be joined or detached at the time the destructor is called. The destructor is invoked when main
exits, and probably assumes that join
or detach
has been called.
The code should also not crash, as long as the following two lines are somewhere after helper1
and helper2
are constructed.
helper1.detach()
helper2.detach()