MIPS R4000 Microprocessor User's Manual 287
Cache Organization, Operation, and Coherency
Figure 11-16 Synchronization with Test-and-Set
The processor begins by loading the semaphore and checking to see if it is
unlocked (set to 0) in steps 1 and 2. If the semaphore is not 0, the processor
loops back to step 1. If the semaphore is 0, indicating the shared data is
not locked, the processor next tries to lock out any other access to the
shared data (step 3). If not successful, the processor loops back to step 1,
and reloads the semaphore.
If the processor is successful at setting the semaphore (step 4), it executes
the critical section of code (step 5) and gains access to the shared data,
completes its task, unlocks the semaphore (step 6), and continues
processing.
1. Load semaphore
2. Unlocked?
(=0?)
3. Try locking
semaphore
4. Successful?
6. Unlock semaphore
5. Execute critical section
(Access shared data)
No
Yes
No
Yes
Continue processing