Ada Code Generation : Main Task—Partition and Flow Control for Ada : Entering the Wait State

Entering the Wait State

If the system has executed two consecutive idle steps, it is in a stationary condition. The reason for executing two idle steps is that the negation of events might yield an active trigger after a single idle state. If the system is idled for two steps, no negative event triggers can take place. At this point, the main task releases the CPU by calling to a system service that blocks it from running until some external stimulus occurs. The external stimulus can be either an event/data change, or a timeout.

The decision whether to enter a wait state or not should be handled carefully, since once the main task blocks itself, only external input wakes it.

 

 

This scenario leads to a deadlock condition. Since the timeout is ignored by the system, the main task has already “decided” to hibernate itself but has not yet done so and the “wake-up” call is lost. The use of the SEMAPHORE task allows for virtual exclusion test-and-block and therefore avoids the deadlock.