Put_Task(a) {
slot = Fetch&Add(FF,1);
if slot == n then Fetch&Add(FF, -n);
if slot > n then slot = slot - n;
while TD[slot] != 0 do wait(rand());
TD[slot] = a;
}
Get_Task { var temp;
slot = Fetch&Add(NA,1);
if slot == n then Fetch&Add(NA,-n);
if slot > n then slot = slot - n;
while TD[slot] == 0 do wait(rand());
temp=TD[slot]; TD[slot]=0; return temp;
}