Simple Software Lock
lock: ld R1,loc -- get fresh value
cmp loc, #0 -- test if it changed
bnz R1,lock -- spin if loc ~ free?
st loc, #1 -- its free, set it
unlock: st loc,#0 -- clear setting
The code seems simple enough, but consider various interleavings