[c++-pthreads] Re: pthread_cancel and EH: let's try this again

Nathan (Jasper) Myers ncm at codesourcery.com
Thu Jul 21 00:09:07 UTC 2005


On Wed, Jul 20, 2005 at 11:24:51PM +0200, Wil Evers wrote:
> Nathan Myers wrote:
> (Is it really 5?  I think so.)
> 
> * Threads are created with cancellation enabled (this is just repeating 
> what POSIX says, I think).
> 
> * Cancellation is sticky: it causes an irreversible state change in the 
> target thread; subsequent cancellations have no further effect.
> 
> * A cancellation exception is a normal C++ exception.  In particular, it 
> can be caught by a catch (...), and there is no requirement that it must 
> be rethrown if caught.
> 
> * A thread's cancellation state is only affected by calls to 
> pthread_setcancelstate() originating from user code.

This strikes me as still unnecessarily complicated.  Do we need a #6?
So be it.  In #6,

 * Threads are initiated with cancellation disabled.

 * Cancellation is sticky. 

 * On construction of a cancellation_context object C, if the thread 
   is in a cancelled state, an ordinary exception is thrown.

 * During the lifetime of C, the semantics of destructors and catch 
   blocks are undefined if the thread is cancelled and a POSIX C 
   cancellation point is encountered.  Any cleanup ends at the scope 
   of C, and control leaves this scope via an ordinary exception.
   
 * Outside the scope of a cancellation_context, the effect of 
   pthread_cleanup_push etc. is undefined.

 * Other context types provided may have different semantics, such 
   as one in which certain system calls fail if the thread is
   cancelled.

This shouldn't need any compiler support, and the thread runtime
shouldn't need to know any details about the exception mechanism.

Nathan Myers
ncm at codesourcery.com



More information about the c++-pthreads mailing list