-
Stop a pthread
I need to know what is the simplest way to stop a pthread. I dont want to use nor I am using mutex lock and unlock, but my threads are running fine and I want to stop the running thread if a global variable is set.
can somebody throw some light on this.
Thanks
-
Re: Stop a pthread
Use pthread_cancel function:
http://www.kernel.org/doc/man-pages/..._cancel.3.html
When pthread_cancel is called from another thread, and one of cancellation points is executed, thread is terminated. Full list of cancellation points:
http://www.kernel.org/doc/man-pages/...threads.7.html
If thread doesn't contain cancellation points (like computation thread), use pthread_testcancel on every iteration.