I’m writing a multi-threaded C++ program. I plan on killing threads. However, I am also using a ref-counted GC. I’m wondering if stack allocated objects get destructed when a thread gets killed.
I’m writing a multi-threaded C++ program. I plan on killing threads. However, I am
Share
The stack does not unwind when you ‘kill’ a thread.
Killing threads is not a robust way to operate – resources they have open, such as files, remain open until the process closes. Furthermore, if they hold open any locks at the time you close them, the lock likely remains locked. Remember, you are likely calling a lot of platform code you do not control and you can’t always see these things.
The graceful robust way to close a thread is to interrupt it – typically it will poll to see if it’s been told to close down periodically, or it’s running a message loop and you send it a quit message.