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:

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.