Cmplr8Mntr2:
MONITOR
EXPORTS Cmplr8Mntr2Defs =
BEGIN
TicketAvailable: CONDITION;
flag: PUBLIC BOOL ¬ FALSE;
ticCnt: CARDINAL ¬ 0;
nullTicket: PUBLIC CARDINAL ¬ 100;
AllocateTicket:
PUBLIC
ENTRY
PROCEDURE
RETURNS [ticket:
CARDINAL] =
BEGIN
WHILE flag DO WAIT TicketAvailable; ENDLOOP;
ticket ¬ TicketGenerator[];
ticCnt ¬ ticCnt + 1;
END;
FreeTicket:
PUBLIC
ENTRY
PROCEDURE =
BEGIN ticCnt ¬ ticCnt - 1; flag ¬ FALSE; NOTIFY TicketAvailable; END;
TicketGenerator:
INTERNAL
PROCEDURE
RETURNS [
CARDINAL] =
BEGIN
IF ticCnt < 10 THEN RETURN[ticCnt]
ELSE BEGIN flag ¬ TRUE; RETURN[nullTicket]; END;
END;