Does the cancel point allow cancellation of these specific API calls?
Sticking to PTHREAD_CANCEL_DEFERRED, this can be a center of confusion. You almost think about it back. The cancellation point does not allow canceling system calls (the API in your item list), and the calls check to see if the cancellation request is waiting. Conceptually, you can think of it as (manually) by setting a switch. Automatic cancel points will check if this is valid, and a deliberate call to pthread_testcancel can be inserted where it is convenient or otherwise - for example, in the middle of a long calculation cycle, where otherwise system calls cannot be canceled. Cancel points automatically force calls for any pthread cleanup handlers that have been configured and that can be bound in a manner similar to atexit calls.
Many people choose (if feasible for their situation) to set their own switch and code as a means of disabling the flow at this point in the flow when checking the switch. PTHREAD_CANCEL_DEFERRED is mainly on steroids. It provides (potentially) several points where this switch is conceptually verified and thereby forces the developer to consider the consequences of canceling at each of these points.
Why are those and not others?
You will need to discuss this on a per-call basis, but primarily because of unpredictable side effects.
Do you want to use user code cancel points or just in the API?
Yes, you want to use them in user level code. You, as a programmer, are in a better position to know what resources you are using, and how to clear them if the stream is canceled, and the logical consequences of canceling at any given point.
PTHREAD_CANCEL_ASYNCHRONOUS is another ball of wax and a nightmare. Conceptually, you can think of it as a thread that exploded with the kill signal - it can be interrupted anywhere, but this allows launching cleanup handlers. The problem is that it is really hard to do, for example, what if it is canceled in the middle of malloc ? This makes it practically worthless outside of some really, really, carefully considered situations.
Duck
source share