struct Test { bool active{true}; void threadedUpdate() { std::this_thread::sleep_for(std::chrono::milliseconds(1)); if(!active)
When the Test instance is initialized, it generates and separates std::thread , which runs in the background. When the same instance is destroyed, the stream mentioned above tries to access the active element, which was destroyed with the instance, causing a failure (and AddressSanitizer backtracking).
Is there a way to stop the dedicated thread on ~Test() ?
The design is bad. How will a thread running in the background until the caller is destroyed be spawned / processed correctly?
c ++ multithreading c ++ 11 stdthread
Vittorio romeo
source share