-- TestMonitoredQueue.Mesa -- written by Paxton. December 1981 -- last written by Paxton. 9-Dec-81 9:50:07 DIRECTORY MonitoredQueue; TestMonitoredQueue: PROGRAM IMPORTS MonitoredQueue = BEGIN OPEN MonitoredQueue; source: MQ _ Create[]; input: REF READONLY TEXT _ "abcdefghijklmnopqrstuvwxyz"; output: REF TEXT _ NEW[TEXT[26]]; Produce: PROC = { -- adds to source FOR i:NAT IN [0..input.length) DO Add[NEW[CHAR _ input[i]],source]; ENDLOOP; Close[source] }; Consume: PROC = { -- moves from source to output DO x: REF ANY _ Remove[source ! EndOfQueue => EXIT]; WITH x SELECT FROM xx: REF CHAR => { output[output.length] _ xx^; output.length _ output.length+1 }; ENDCASE => ERROR; ENDLOOP }; Test: PROC = { p1: PROCESS _ FORK Produce; p2: PROCESS _ FORK Consume; ok: BOOLEAN; JOIN p1; JOIN p2; ok _ FALSE; Add[NIL, source ! QueueClosed => { ok _ TRUE; CONTINUE }]; IF ~ok THEN ERROR; IF input.length # output.length THEN ERROR; FOR i:NAT IN [0..input.length) DO IF input[i] # output[i] THEN ERROR; ENDLOOP; -- make sure can reuse the queue Reset[source]; output.length _ 0; p1 _ FORK Produce; p2 _ FORK Consume; JOIN p1; JOIN p2; ok _ FALSE; Add[NIL, source ! QueueClosed => { ok _ TRUE; CONTINUE }]; IF ~ok THEN ERROR; IF input.length # output.length THEN ERROR; FOR i:NAT IN [0..input.length) DO IF input[i] # output[i] THEN ERROR; ENDLOOP; }; Test; END.