OSF DCE Application Development Guide--Core Components
Using the DCE Threads Exception-Returning Interface
Note that a CATCH_ALL handler and RERAISE could be used to do this, but the
epilogue code would then have to be duplicated in two places, as follows:
TRY
try_block
CATCH_ALL
final_block
RERAISE;
ENDTRY
{ final_block }
A FINALLY statement has exactly this meaning, but avoids code duplication.
Note: The behavior of FINALLY along with the CATCH or CATCH_ALL
clauses is undefined. Do not combine them for the same try_block.
Another example of the FINALLY statement is as follows:
pthread__mutex_lock (some_object.mutex);
some_object.num_waiters = some_object.num_waiters + 1;
TRY
while (! some_object.data_available)
pthread_cond_wait (some_object.condition);
/* The code to act on the data_available goes here */
FINALLY
some_object.num_waiters = some_object.num_waiters - 1;
pthread_mutex_unlock (some_object.mutex);
ENDTRY
In the preceding example, the call to pthread_cond_wait() could raise the
pthread_cancel_e exception. The final_block ensures that the shared data associated
with the lock is correct for the next thread that acquires the mutex.
9.2 Invoking the Exception-Returning Interface
To use the exception-returning interface, replace the first statement that follows with the
second:
#include <pthread.h>
#include <pthread_exc.h>
124245 Tandem Computers Incorporated 9−3