what will be alternative of pthread_setcanceltype in windows thread programming in c++?
views:
34answers:
2You could use events as synchronization objects. Check in your thread, from time to time the status of event (WaitForSingleObject with zero timeout), and if it is signaled, return from the thread's main function. To cancel the thread from outside, just set the event.
Windows threads do not have cancellation points, so theres no system cancel type to consider.
As such, "canceling" a thread on windows means that you, the developer, needs to come up with a strategy for telling a thread to exit. If it is a GUI thread, you can post it a WM_QUIT message. If it is a non GUI thread, then it really depends on what the thread is doing. You need to analyse the thread and see if there is a point where your code can explicitly check if it needs to keep going, or exit.
There is a pthreads-win32 implementation available if you'd rather avoid the question and get pthreads complaint behaviors on Win32.