Asynchronous cancellation of threads is, in general, evil. The reason for this is that it is usually difficult or impossible to guarantee that the recipient of an asynchronous cancellation request will not be in a critical section. If a thread should die in the middle of a critical section, this will almost certainly cause your program to misbehave.
Code that can deal sensibly with asynchronous cancellation requests is not referred to as async-safe; that means something else (see the glossary section of the FAQ). You won’t see much code around that handles asynchronous cancellation requests properly, and you shouldn’t try write any of your own unless you have compelling reasons to do so. Deferred cancellation is your friend.
Leave a Reply