I am trying to learn std::threads
from C++11
to make a threading system.
I was wondering if there is a way to stop a thread from running (N
There is no way to non-cooperatively stop a thread from running with standard C++. That doesn't mean it's impossible, but you may need to go back to your systems native handle.
For a standard conforming way you can use synchronization primitives (e.g. an std::atomic
) to set a kill flag from the outside and read it within the thread. But it still has to be the thread that finishes on its own.