img
. .
Chapter 9. Cancellation
·
What Cancellation Is
·
INTERRUPT()
·
A Cancellation Example
·
Using Cancellation
·
Cleanup
·
Implementing EnableInterrupts()
·
A Cancellation Example (Improved)
·
Simple Polling
·
APIs Used in this Chapter
·
The Class java.lang.Thread
·
The Class Extensions.InterruptibleThread
In which we describe the acrimonious nature of some programs and how unwanted threads may be
disposed of. The highly complex issues surrounding bounded time termination and program
correctness are also covered. A simple conclusion is drawn.
What Cancellation Is
Sometimes you have reason to get rid of a thread before it has completed its work. Perhaps the
user changed her mind about what she was doing. Perhaps the program had many threads doing a
heuristic search, and one of them found the answer. Perhaps it's time to shut down a server. In
such cases you want to be able to have one thread kill the other threads. This is known as
cancellation (a POSIX term; see Figure 9-1).
Figure 9-1. Thread Cancellation
No matter how you choose to deal with the issues of cancellation, be it in Java, Win32, or POSIX
threads, the primary issues remain the same. You must ensure that any thread that you are going to
cancel releases any locks it might hold, frees any memory it may have allocated for its own use,
and leaves the world in a consistent state (Code Example 9-1).
Example 9-1 Asynchronous Thread Cancellation
POSIX
Java
Win32
T1.stop()
pthread_cancel(T1)
TerminateThread(T1)
Search WWH :
Custom Search
Previous Page
Multithreaded Programming with JAVA - Topic Index
Next Page
Multithreaded Programming with JAVA - Bookmarks
Home