Saturday, April 28, 2007

Cancelable operations

There are many cancelable operations in software system with user interaction, such as cancel auto tunning in TV. The implementation mechanisms of cancelable operations are as follow:

  1. message
    The "cancel" message is sent to thread which do long-time job if necessary. While the function which do long-time job must check whether there are "cancel" message received, if so, the function must stop working and return.

    Cons:
    • It isn't native programming model in Linux/Unix, so third party software will not use it.
    • Can't cancel work in kernel (for example the sleep or block read can not be interrupted)
  2. signal / real time signal
    The "cancel" signal is sent to thread which do long-time job if neccesary. Upon the signal is received, the blocked operation (such as sleep, blocked read, etc) will be interrupted and a signal action function will be called which set a flag to indicate the canel signal is received by the thread. The function which do long-time job must check the flag to see whether there are "cancel" signal received, if so, the function must stop working and return.

    Pros:
    • Native programming model in Linux/Unix, easy to cooperate with third party software.
    • Can cancel work in kernel.

Problems:
  • race conditions !!!

No comments: