Buzz Loops

Several of the event-related statements allow a process to test the state of an event without causing the process to wait. These are the happened test, the availability test, the conditional procure statement, and the partial liberate statement.

These statements are designed for occasional, rather than frequent, use because each execution of the statement uses processor time. In particular, looping continuously on these statements is a very inefficient way of making a process wait. Such a loop is called a buzz loop. The following is an ALGOL example of such a loop:

 WHILE NOT HAPPENED (E1) DO;

This loop repeats the happened test over and over until the event E1 attains a state of HAPPENED. This loop causes two problems:

  • It wastes processor time that could be devoted to executing other processes, including the process that will eventually cause the event.

  • On a single-processor system, it could become an infinite loop. Assume that another process is supposed to cause event E1. If the looping process has higher priority, it will completely monopolize the processor. The second process never executes and thus never causes event E1.

Replace the buzz loop with some form of the wait statement, which does not use any processor time. The ALGOL statement WAIT (E1) could replace the loop shown in the preceding example.