117
The test-and-set instruction
nA C++  description of test-and-set:
nAn algorithm that uses testset for Mutual Exclusion: nShared variable b is initialized to 0 nOnly the first Pi who sets b enter CS
bool testset(int& i)
{
  if (i==0) {
    i=1;
    return true;
  } else {
    return false;
  }
}
Process Pi:
repeat
  repeat{}
  until testset(b);
     CS
  b:=0;
     RS
forever