-- MOSSIMCharFIFODriver.sak -- last edited by Suzuki: 14-Dec-81 10:26:38 DIRECTORY MOSSIMFIFO: TYPE, Connector: TYPE, SimIO: TYPE; MOSSIMCharFIFODriver: MONITOR IMPORTS Connector, MOSSIMFIFO, SimIO = BEGIN Reader: PROC [DataAv: Connector.Handle, DataOut: Connector.Handle, Done: Connector.Handle, ReadReq: Connector.Handle] = { criticalSection3: ENTRY PROC = { Connector.Put[ReadReq, NEW[BOOLEAN ← TRUE]]}; SimIO.WF0[" Reader started.*n"]; THROUGH [0..30) DO Connector.GetNew[Done, TRUE]; criticalSection3[]; FOR i: NAT IN [0..16) DO SimIO.WF1 ["%u", NARROW[Connector.Get[DataOut], REF ARRAY INTEGER [0..16) OF CHARACTER]↑[i]] ENDLOOP; SimIO.WF0[" "]; Connector.Put[ReadReq, NEW[BOOLEAN ← FALSE]] ENDLOOP; SimIO.WF0[" Reader terminated.*n"]; Connector.ProcessEnd[]}; Writer: PROC [SpaceAv, Done: Connector.Handle, WriteReq: Connector.Handle, DataIn: Connector.Handle] = { i: CARDINAL; criticalSection4: ENTRY PROC = { {Connector.Put[DataIn, NEW[CARDINAL ← i]]; Connector.Put[WriteReq, NEW[BOOLEAN ← TRUE]]}}; SimIO.WF0[" Writer started.*n"]; FOR i IN [0..30) DO Connector.GetNew[Done, TRUE]; criticalSection4[]; SimIO.WF1["%u- ", i]; Connector.Put[WriteReq, NEW[BOOLEAN ← FALSE]] ENDLOOP; SimIO.WF0[" Writer terminated.*n"]; Connector.ProcessEnd[]}; Start: PROC [Init, ReadReq, WriteReq, DataIn: Connector.Handle] = { Connector.Put[ReadReq, NEW[BOOLEAN ← FALSE]]; Connector.Put[WriteReq, NEW[BOOLEAN ← FALSE]]; Connector.Put[DataIn, NEW[CARDINAL ← 0]]; Connector.Delay[10]; Connector.Put[Init, NEW[BOOLEAN ← TRUE]]; Connector.Delay[5]; Connector.Put[Init, NEW[BOOLEAN ← FALSE]]; Connector.ProcessEnd[]}; SimIO.Start["FIFO.jam"]; {init: Connector.Handle ← Connector.Create[]; write: Connector.Handle ← Connector.Create[]; read: Connector.Handle ← Connector.Create[]; in: Connector.Handle ← Connector.Create[]; space: Connector.Handle ← Connector.Create[]; data: Connector.Handle ← Connector.Create[]; out: Connector.Handle ← Connector.Create[]; done: Connector.Handle ← Connector.Create[]; fifo, reader, writer, start: PROCESS; Connector.IncCurrent[]; fifo ← FORK MOSSIMFIFO.FIFOFunc[size: 100, Init: init, WriteRequest: write, ReadRequest: read, DIn: in, SpaceAv: space, DataAv: data, DOut: out, Done: done]; Connector.IncCurrent[]; reader ← FORK Reader[DataAv: data, DataOut: out, ReadReq: read, Done: done]; Connector.IncCurrent[]; writer ← FORK Writer[SpaceAv: space, Done: done, WriteReq: write, DataIn: in]; Connector.IncCurrent[]; start ← FORK Start[Init: init, ReadReq: read, WriteReq: write, DataIn: in]; [] ← JOIN fifo; [] ← JOIN reader; [] ← JOIN writer; [] ← JOIN start}; SimIO.Stop[] END.