declare fun {NewLock} Token={NewCell unit} CurThr={NewCell unit} proc {Lock P} if {Thread.this}==@CurThr then {P} else Old New in {Exchange Token Old New} {Wait Old} CurThr:={Thread.this} try {P} finally CurThr:=unit New=unit end end end in 'lock'('lock':Lock) end