Back to Techniques for mutual exclusion:
test & set lock (TSL)   (pages 62 to 63)                  (use hardware to take care)
  tsl register, lock
     Do the following jobs atomically (they can not be broken apart):


The following is an assembly language:
 

loop:
      tsl  register, lock
      cmp  register, #0
      jne  loop

How to leave region:

      move lock, #0


The following is another version of test & set lock (TSL) :

Special Hardware Instruction: Atomically executed in micro-code.
boolean test-and-set(boolean &target)
{
   boolean temp = target;
   target = true;
   return temp;
}

boolean lock = false;
while(true)
{
  while(test-and-set(lock)) ;
      Critical Section
  lock = false;
      Remainder Section
}