Implementing critical section
We have a testandset instruction: Using testandset instruction
High level function:
- Takes a memory location, returns the current contents.
- Set the contents of the memory location to 1.
void EnterCS(int *Lock)
{
while( TestAndSet(Lock) == 1 ); // Busy waiting
}
void ExitCS(int *Lock)
{
*Lock = 0;
}
Similar:
Compare and Exchange Atomic Swap Load Link / Store conditional