[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]


B.12.7 Image Exit

In processes that use threading, image exit occurs as follows: $EXIT does not immediately invoke exit handler routines. Instead, it results in an upcall which causes DECthreads to schedule a special thread to execute the exit handler routines. $EXIT then calls pthread_exit() to terminate the calling thread. This allows it to release any resources that it might be holding.

The exit handler routines are executed in a separate thread to avoid entering a deadlock situation. For example, if the thread that called $EXIT did so while holding a mutex which is required by an exit handler routine, then the exit handler routine would cause the thread to block forever, waiting for a mutex that it already holds. Having the exit handler executed in a separate thread allows that thread to block while the thread holding the mutex cleans up.

$FORCEX works in an analogous fashion. Instead of invoking $EXIT directly, it causes an upcall that allows DECthreads to release the exit-handler thread.

DCL Control-Y continues to work as it always has on multithreaded applications. However, typing EXIT or issuing any other command that invokes a new image causes the $FORCEX upcall. While this is an improvement over the pre-Version 7.0 behavior in many cases, it does not guarantee that the multithreaded application will exit. For example, if the application is deadlocked, holding a resource required by one of the exit handler's routines, the application will continue to hang - even after typing Control-Y and EXIT. In these cases, type Control-Y again and issue the STOP command. This will terminate the application without running exit handlers. Note that the application will be unable to clean up, and it may leave data files and the terminal in an inconsistant state.