Chapter 11
288 MIPS R4000 Microprocessor User's Manual
Counter
Another common synchronization technique uses a counter. A counter is a
designated memory location that can be incremented or decremented.
In the test-and-set method, only one processor at a time is permitted to
enter the critical section. Using a counter, up to N processors are allowed
to concurrently execute the critical section. All processors after the Nth
processor must wait until one of the N processors exits the critical section
and a space becomes available.
The counter works by not allowing more than one processor to modify it
at any given time. Conceptually, the counter can be viewed as a variable
that counts the number of limited resources (for example, the number of
processes, or software licenses, etc.). Figure 11-17 shows this process.
Figure 11-17 Synchronization Using a Counter
Load counter
Successful?
Try decrementing
No
Yes
Execute critical section
Counter > 0?
Yes
No
counter
Load counter
Try incrementing
counter
Successful?
No
Yes
Continue processing