Sign in to follow this  

end thread externally(C++)

Recommended Posts

Generally speaking, it's bad form to end a thread "externally," as that thread may be in the middle of any number of operations that should be cleaned up (file io, memory allocation, etc.). What you should do is provide a safe way to communicate with your thread that it should quit whatever it's doing, such as a shared atomic of some sort (could conceivably just be a bool, or an event/semaphore). Your external thread sets this to true when it wants the thread to end, and the thread checks this at various points when it is safe to terminate.

If you really really have to end the thread externally, there are ways... under windows you can call TerminateThread... I'm not sure if there is an equivalent for the "_beginthread" API.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this