Completing a Cancellation Request
To complete the cancellation request, the thread executing inside the runnable must call the
serviceCancellation() function provided by the
RWRunnableSelf handle class. If there is an outstanding cancellation request, this function throws an
RWCancellation exception object; otherwise the function simply returns to the caller. A thrown cancellation object notifies the current runnable that cancellation has started, causing the runnable’s execution state to change to
RW_THR_CANCELING[10].
At this point, the C++ exception processing begins unwinding the call-stack until an exception handler is found for the
RWCancellation object. If the code that was executing inside the runnable does nothing to stop the unwind, the cancellation exception propagates all the way back out of the runnable’s
run() member and into exception-handling code inside the runnable class. If this happens, the cancellation process concludes, and the requesting thread is notified that cancellation has completed successfully.
When a runnable is canceled, its completion state is changed to
RW_THR_CANCELED{4}, its execution state is reset back to the
RW_THR_INITIAL[11], and an
RWTHROperationCanceled exception is stored for retrieval by
raise().