Boost logo

Boost :

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:

http://www.tru64unix.compaq.com/docs/base_doc/DOCUMENTATION/V51_HTML/ARH9RBTE/DOCU0004.HTM#cancel_sec

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 2.3.7.4 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 2.3.7.3 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.

2.3.7.1 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.

http://www.tru64unix.compaq.com/docs/base_doc/DOCUMENTATION/V51_HTML/ARH9RBTE/DOCU0009.HTM#excep_relation

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