Synchronization

Peterson's Algorithm

Works on uniproccessor systens.
If we have two threads, T0, T1 and a turn-variable = 0 and a lock-variable = []
If a thread wants the lock it will set the lock-variable to true. The turn-variable says hich thread is in control of the lock.

  1. Set lock_(tID) to true
  2. Set turn to 1 (set turn to the other tID)
  3. While (lock - tID) && turn == 1 - tID
  4. At this point T0 has the lock

XCHG

Spinlock

Pros

Cons