Starvation and Blocking
This example uses the li's channel viewer to demonstrate the
phenomenon of starvation and blocking. This simple program reads two
delay values from the user and starts processes that send and receive
on a channel with the specified cycle times:
use(channels).
ts:var(int).
tr:var(int).
C:var(chan(void)).
init_chan(C,"C");
print("Enter cycle time for sender:\n");
ts:=readint;
print("Enter cycle time for receiver:\n");
tr:=readint;
(
forever(
C!null;
wait_for(ts)
)
)
|
(
forever(
C?null;
wait_for(tr)
)
)
Here's one example run under li. In this case the user has given
delays of 25 and 35 time units for sender and receiver respectively,
and the resulting display is as follows:

Here is the result when the sender's delay is 50 time units and the
receiver is only 10:

The traces can be interpretted as follows:
- The red bars in the upper half of the trace represent the
sender's activity. The start of the red bar indicates the point where
the sender was ready to start a communication. The end of the red bar
indicates where the communication finished.
- The blue bars in the lower half of the trace represent the
receiver's activity. The start of the blue bar indicates the point
where the receiver became ready to accept a communication. The end of
the blue bar indicates where the communication finished.
So a trace containing a lot of red bars, such as the first of the
examples above, indicates a system where the sender is blocked by the
relatively slow receiver. On the other hand a trace containing a lot
of blue bars, such the the second above, indicates a system where the
receiver is starved by the relatively slow sender.