Next: Synchronous and Asynchronous Threads
Up: Threads
Previous: Thread Attributes
Contents
- It is possible for a thread to request that another thread terminate.This is called canceling a thread.
- To cancel a thread, call pthread_cancel, passing the thread ID of the thread to be canceled. A canceled thread may later be joined; in fact, you should join a canceled thread to free up its resources, unless the thread is detached.
- Often a thread may be in some code that must be executed in an all-or-nothing fashion.
- If the thread is canceled in the middle of this code, it may not have the opportunity to deallocate the resources, and thus the resources will be leaked.
- A thread may be in one of three states with regard to thread cancellation.
- asynchronously cancelable. The thread may be canceled at any point in its execution.
- synchronously cancelable. The thread may be canceled, but not at just any point in its execution. Instead, cancellation requests are queued, and the thread is canceled only when it reaches specific points in its execution. These points are called cancellation points.
- uncancelable. Attempts to cancel the thread are quietly ignored.
- When initially created, a thread is synchronously cancelable.
Subsections
Next: Synchronous and Asynchronous Threads
Up: Threads
Previous: Thread Attributes
Contents
Cem Ozdogan
2007-05-16