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


2.1.3 Termination

Termination occurs when a thread returns from its start_ routine function or calls pthread_exit. In the case of a termination, the following actions are performed:

  1. The return value of the start routine function is copied into the thread object. This value can be obtained when another thread later calls the pthread_join routine. If the start routine returns normally and is a procedure that does not return a value, then the return value obtained by pthread_join will be unpredictable.

  2. In the pthread interface to DECthreads, each cleanup handler that has been declared by pthread_cleanup_push and not yet removed by pthread_cleanup_pop is called. The most recently pushed handler is called first. Thread exit is accomplished by raising the exception pthread_exit_e. Using CATCH handlers in place of pthread_cleanup_push has the same effect, but is not portable.

  3. Each thread-specific data destructor is removed from the list of destructors for this thread, and then is called. This step destroys all the thread-specific data associated with the current thread. See Section 2.5 for more information on thread-specific data.

  4. Any thread currently waiting in a call to pthread_join for the terminating thread is awakened.

  5. The thread object is marked to indicate that it is no longer needed by the thread itself. A check is made to determine if the thread is detached. If so, then the thread object is deallocated. Otherwise, the thread object is retained until it is detached.