OS Concepts · Chapter 6

Synchronization Hardware

A hardware-provided atomic TestAndSet instruction builds a simple spinlock.

What's happening

TestAndSet(&lock) atomically reads the old value of lock and sets it true in one indivisible step. A process spins in a while-loop until it reads back false, meaning it just acquired the lock. Simple, but gives no fairness guarantee — a process could in theory spin forever.

Shared state

Synchronization Hardware

0 / 0
Speed
🔓
lock = false
P0 critical section
—
P1 critical section
—

Event log