CRCR and STOQ Events in ALGOL

The following ALGOL program fragment demonstrates the use of CRCR and STOQ events in a WAIT statement:

REPLACE PROGNAME BY “OBJECT/EPSILON”;
EVORDER:= 1;
DONE:= FALSE;
WHILE NOT DONE DO
BEGIN
   EVT:= WAITANDRESET (CRCR_INPUT “OBJECT/DELTA”,
                        CRCR_OUTPUT PROGNAME,
                        STOQ_INPUT STOQ_ALPHA,
                        STOQ_OUTPUT STOQ_BETA,
                        MYSELF.ACCEPTEVENT) [EVORDER];
   CASE EVT OF
   BEGIN
      1: %... Call the CRCR_RECV procedure
      2: %... Call the CRCR_SEND procedure
      3: %... Call the STOQ_RECV procedure
      4: %... Call the STOQ_SEND procedure
      5: DONE:= TRUE;
   END;
   EVORDER:= * + 1;
   IF EVORDER > 4 THEN
      EVORDER:= 1;
END;

In this example, the WAIT statement waits on several different events: CRCR_INPUT, CRCR_OUTPUT, STOQ_INPUT, STOQ_OUTPUT, and MYSELF.ACCEPTEVENT.

The STOQ_INPUT and STOQ_OUTPUT events in the WAIT statement refer to the STOQ parameter blocks STOQALPHA and STOQBETA, declared previously in the program. The statements that initialize STOQALPHA and STOQBETA are omitted from the example.

The EVORDER variable specified in the WAIT statement indicates the first event to be tested for a HAPPENED state. Because the EVORDER value is changed after each WAIT statement, the WAIT statement tests a different event first each time it is executed. This technique prevents starvation problems, as discussed in Preventing Starvation Problems under Using Events and Interlocks.