Shutting Down a Continuous Process
An interrupt can be used to shutdown a continuous, iterative process by using the
serviceInterrupt() routine to control the process iteration, as in
Example 8.
Example 8 – Using an interrupt to shut down a continuous process
.
.
.
RWRunnableSelf self = rwRunnable();
// Perform iterative operation until interrupted...
while(!self.serviceInterrupt()) {
// Perform operation
}
// Operation interrupted!
.
.
.
To shutdown the iterative process, an external thread calls requestInterrupt() and follows that with a call to releaseInterrupt():
.
.
.
// "theThread” is the iterative process
// Request shutdown!
if (RW_THR_ABORTED == theThread.requestInterrupt()) {
// Oops! The process isn’t running anymore!
}
else {
theThread.releaseInterrupt();
}
.
.