Waiting on Multiple Events

The wait statement can specify a list of events. The process waits until any one of the events is caused. If any one of the events is already HAPPENED when the wait statement is executed, the process does not wait at all. The wait statement can return a value that specifies which one of the events was caused. If more than one of the events was caused, the value returned indicates the leftmost of the caused events in the list.

A wait and reset statement can also wait on multiple events. This statement resets to NOT HAPPENED the single event that reactivates the process.

ALGOL and COBOL85 programs can optionally specify which of the events in a WAIT statement should be tested first. COBOL74 does not offer this feature. This feature can help prevent starvation problems of the type described under Preventing Starvation Problems later in this section.

The following ALGOL statement waits for 10 seconds, or until event E1 or E2 is caused, whichever comes first. The variable EVCOUNT specifies which of the three events listed should be tested first. The relative position of the event that reactivates the process is stored in T. For example, if E1 reactivates the process, T receives a value of 2.

T:= WAIT ((10), E1, E2) [EVCOUNT];

The following COBOL85 statement has the same effect:

WAIT UNTIL 10, E1, E2 USING EVCOUNT GIVING T.

The USING EVCOUNT clause would be omitted in COBOL74, as this language does not support this feature.

ALGOL also supports an INTERRUPTIBLE option in WAIT or WAITANDRESET statements. This option causes the statement to return if a signal is received before any of the other events are caused. For information about the use of this option, refer to the POSIX User's Guide.