I just had this problem, so I am posting a real answer to others.
In the visual studio, at least there is an βexit lockβ that blocks when the thread enters the exit code (that is, after main() for the main thread and after f() for std::thread(f) ).
Since your test class is destroyed only after main() , blocking the output is blocked. Only after that will you set mExit = true; and another thread will be completed. Then this other thread waits for an βexit lockβ that is already taken by the main thread, while the main thread waits in mThread.join(); leading to a deadlock.
So yes, you need to attach all your threads before the main thread completes.
god
source share