From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2001-08-04 10:33:10
> Anyway, as I said, I haven't been following closely. There's no reason an
> exception couldn't be used within a thread to interrupt it,
and Compaq already does it:
2.3.7 Canceling a Thread
Canceling a thread means requesting the termination of a target
thread as soon as possible. A thread can request the cancelation
of another thread or itself.
Thread cancelation is a three-stage operation:
A cancelation request is posted for the target thread. This occurs
when some thread calls pthread_cancel() . The posted cancelation
request is delivered to the target thread. This occurs when the
target thread invokes a routine that is a cancelation point.
(See Section 18.104.22.168 for a discussion of routines that are
cancelation points.) If the target thread's cancelability state
is disabled, the target thread does not receive the cancelation
request until the next cancelation point after the cancelability
state is set to enabled. See Section 22.214.171.124 for how to control
a thread's cancelability.
The target thread might have pushed cleanup handler routines
(using the pthread_cleanup_push() routine) on its handler stack.
When the target thread receives the cancelation request,
the Threads Library unwinds the thread's call stack. For each
frame, active exception handlers are invoked. These include cleanup
handler routines, C++ object destructors, Compaq C SEH except
clauses, and C++ catch(...) clauses.
126.96.36.199 Thread Cancelation Implemented Using Exceptions
The Threads Library implements thread cancelation using exceptions.
Using the exception package, it is possible for a thread (to which
a cancelation request has been delivered) explicitly to catch the
thread cancelation exception ( pthread_cancel_e ) defined by the
Threads Library and to perform cleanup actions accordingly. After
catching this exception, the exception handler code should always
reraise the exception, to avoid breaking the "contract" that
cancelation leads to thread termination.
5.1.2 Relation of Exceptions to Return Codes and Signals
The Threads Library uses exceptions in the following cases:
The pthread_exit() routine raises the exception pthread_exit_e
defined by the Threads Library.
Canceling a thread causes the Threads Library to raise the
exception pthread_cancel_e defined by the Threads Library.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk