For some (embedded) applications you may want to control the scheduling of processes.

In this example, we show how a program with 4 processes may be scheduled using a mix of cooperative and preemptive scheduling.

The example has 2 processes, F and keyboard that must be scheduled regularly and decide themselves when to suspend. The Keyboard is described on the next page.

When F and keyboard are not running, two other processes P1 and P2 may run, but these are bot preempted after some time.

MixedScheduling: =  LIB.BasicSystem.BasicSystem 
   F: = BasicProcess("F")
          -- do something
          %if done %then% F.suspend
   P1: = BasicProcess("P1")
          -- do something until preempted
   P2 : = BasicProcess("P2")
          -- do something until preempted

The object MixedScheduling, constantly executes a loop (using cycle):

  1. The objects keyboard and F are resumed.
  2. Then P1 and P2 are attached and preempted after 10 time units. 

Supposed that keyboard and F together use 5 time units, then keyboard and F are guaranteed to be executed every 25 time units.

The objects F, P1 and P2 may read characters from the keyboard, and since keyboard is non-blocking they will be suspended if no input is available.