Start with a simple software lock
Shared: lock = 0;
Acquire : while (lock); lock = 1;
Release or Unlock : lock = 0;
Lock: lw register, lock_addr /* register is any processor register */
bnez register, Lock
addi register, register, 0x1
sw register, lock_addr
Unlock: xor register, register, register
sw register, lock_addr