Simple Test&Set Lock
lock: t&s register, location
bnz lock /* if not 0, try again */
ret /* return control to caller */
unlock: st location, #0 /* write 0 to location */
ret /* return control to caller */
Other read-modify-write primitives
- Swap
- Fetch&op
- Compare&swap
- Three operands: location, register to compare with, register to swap with
- Not commonly supported by RISC instruction sets