Bounded-waiting with TestAndSet(). Taken from Bell, John T. "Process Synchronization." University of Illinois, Chicago.