The cancelability of a thread determines when, if ever, it acts upon
cancellation requests [see _p_t_h_r_e_a_d__c_a_n_c_e_l(), and _p_t_h_r_e_a_d__e_x_i_t()].
Cancellation state may be either PPPPTTTTHHHHRRRREEEEAAAADDDD____CCCCAAAANNNNCCCCEEEELLLL____EEEENNNNAAAABBBBLLLLEEEE or
PPPPTTTTHHHHRRRREEEEAAAADDDD____CCCCAAAANNNNCCCCEEEELLLL____DDDDIIIISSSSAAAABBBBLLLLEEEE. If it is PPPPTTTTHHHHRRRREEEEAAAADDDD____CCCCAAAANNNNCCCCEEEELLLL____DDDDIIIISSSSAAAABBBBLLLLEEEE, then
cancellation requests are blocked (held pending) indefinitely. If the
state is PPPPTTTTHHHHRRRREEEEAAAADDDD____CCCCAAAANNNNCCCCEEEELLLL____EEEENNNNAAAABBBBLLLLEEEE, the cancellation type is the governing
factor.
Cancellation type may be either PPPPTTTTHHHHRRRREEEEAAAADDDD____CCCCAAAANNNNCCCCEEEELLLL____AAAASSSSYYYYNNNNCCCCHHHHRRRROOOONNNNOOOOUUUUSSSS or
PPPPTTTTHHHHRRRREEEEAAAADDDD____CCCCAAAANNNNCCCCEEEELLLL____DDDDEEEEFFFFEEEERRRRRRRREEEEDDDD. The type only affects the cancelability of a
thread if the cancellation state is PPPPTTTTHHHHRRRREEEEAAAADDDD____CCCCAAAANNNNCCCCEEEELLLL____EEEENNNNAAAABBBBLLLLEEEE.
If the type is PPPPTTTTHHHHRRRREEEEAAAADDDD____CCCCAAAANNNNCCCCEEEELLLL____DDDDEEEEFFFFEEEERRRRRRRREEEEDDDD, cancellation requests are only
acted on when the thread is in a known state, namely that it enters or is
waiting in a set of functions known as cancellation points (see NNNNOOOOTTTTEEEESSSS).
Usually these are functions in which a thread may block for an unbounded
period of time. If the cancellation request is acted upon at a
cancellation point, the operation associated with the function is
aborted. For example, if a _r_e_a_d() is in progress when the thread is
cancelled, then either the _r_e_a_d() will return data or the cancellation
will be acted upon. Should the thread read data before the request
arrives, it will not be cancelled.
If the type is PPPPTTTTHHHHRRRREEEEAAAADDDD____CCCCAAAANNNNCCCCEEEELLLL____AAAASSSSYYYYNNNNCCCCHHHHRRRROOOONNNNOOOOUUUUSSSS, then cancellation requests
may take effect immediately. This type of cancellation should only be
used when the state of target thread is known. If the target thread is
executing exclusively in user code (for example in a computation loop)
this is safe. However, this is not the case if the thread makes calls to
a library. For this reason deferred cancellation should be preferred to
asynchronous cancellation.
Cancellation handlers [see _p_t_h_r_e_a_d__c_l_e_a_n_u_p__p_u_s_h()] can be used to restore
application state when a thread is cancelled.
When threads start, their cancellation state is PPPPTTTTHHHHRRRREEEEAAAADDDD____CCCCAAAANNNNCCCCEEEELLLL____EEEENNNNAAAABBBBLLLLEEEE and
their cancellation type is PPPPTTTTHHHHRRRREEEEAAAADDDD____CCCCAAAANNNNCCCCEEEELLLL____DDDDEEEEFFFFEEEERRRRRRRREEEEDDDD.
The _p_t_h_r_e_a_d__s_e_t_c_a_n_c_e_l_s_t_a_t_e() function changes the calling thread's
cancellation state to _n_e_w__s_t_a_t_e which can be either
PPPPTTTTHHHHRRRREEEEAAAADDDD____CCCCAAAANNNNCCCCEEEELLLL____DDDDIIIISSSSAAAABBBBLLLLEEEE or PPPPTTTTHHHHRRRREEEEAAAADDDD____CCCCAAAANNNNCCCCEEEELLLL____EEEENNNNAAAABBBBLLLLEEEE. If _o_l_d__s_t_a_t_e is not
NNNNUUUULLLLLLLL, then it is used to return the previous state. If the state is
changed to PPPPTTTTHHHHRRRREEEEAAAADDDD____CCCCAAAANNNNCCCCEEEELLLL____EEEENNNNAAAABBBBLLLLEEEE and there is a cancellation request
pending, then it will be acted on immediately.
The _p_t_h_r_e_a_d__s_e_t_c_a_n_c_e_l_t_y_p_e() function changes the calling thread's
cancellation type to _n_e_w__t_y_p_e which can be either
PPPPTTTTHHHHRRRREEEEAAAADDDD____CCCCAAAANNNNCCCCEEEELLLL____AAAASSSSYYYYNNNNCCCCHHHHRRRROOOONNNNOOOOUUUUSSSS or PPPPTTTTHHHHRRRREEEEAAAADDDD____CCCCAAAANNNNCCCCEEEELLLL____DDDDEEEEFFFFEEEERRRRRRRREEEEDDDD. If _o_l_d__t_y_p_e is
not NNNNUUUULLLLLLLL, then it is used to return the previous type.
The _p_t_h_r_e_a_d__t_e_s_t_c_a_n_c_e_l() function is a cancellation point. If
cancellation is enabled and a cancellation request is pending on the
thread, then calling this function will terminate the thread.
DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
The functions _p_t_h_r_e_a_d__s_e_t_c_a_n_c_e_l_s_t_a_t_e() and _p_t_h_r_e_a_d__s_e_t_c_a_n_c_e_l_t_y_p_e() return