DIRECTORY
	FIFO,
	FIFOGuardian,
	Process,
	RandomCard,
	WF;

FIFODriver: MONITOR
	IMPORTS FIFO, FIFOGuardian, Process, RandomCard, WF = {

p,q,r: PROCESS;
i: CARDINAL;

Reader: PROC = {
	WF.WF0["  Reader started.*n"];
	[] ← RandomCard.InitRandom[-1];
	THROUGH [0..50) DO
		Process.Yield[];
		UNTIL FIFO.DataAvQ[] DO Process.Yield[] ENDLOOP;
		FIFOGuardian.SetReadRequest[TRUE];
		WF.WF1["%u  ", FIFO.GetDataOut[]];
		Process.Yield[];
		FIFOGuardian.SetReadRequest[FALSE];
	ENDLOOP;
	WF.WF0["  Reader terminated.*n"];
	};
Writer: PROC = {
	WF.WF0[" Writer started.*n"];
	[] ← RandomCard.InitRandom[-1];
	FOR i IN [0..50) DO
		Process.Yield[];
		UNTIL FIFO.SpaceAvQ[] DO Process.Yield[] ENDLOOP;
		FIFOGuardian.SetDataIn[i];
		FIFOGuardian.SetWriteRequest[TRUE];
		WF.WF1["%u-  ", i];
		Process.Yield[];
		FIFOGuardian.SetWriteRequest[FALSE];
	ENDLOOP;
	WF.WF0[" Writer terminated.*n"];
	};

START FIFO.FIFOImpl;
r ← FORK FIFO.Main[];
FIFO.SetInit[FALSE];
p ← FORK Reader[];
q ← FORK Writer[];

[] ← JOIN p;
[] ← JOIN q;
}.