operating-systems hardware concurrency

Definition

Test-and-Set

Test-and-set is a hardware instruction providing atomic read-modify-write access to a memory location. Essential for implementing mutual exclusion in multiprocessor environments.

Implementation

Spinlock

// Global: int lock = 0;
 
// Process Pi
while (testset(&lock) == false);  // Busy waiting
// --- Critical Section ---
lock = 0;                         // Release lock
// --- Remainder Section ---

Properties

Simplicity

Provides a simple entry protocol for critical sections.

No Bounded Waiting

Ensures mutual exclusion but does not guarantee bounded waiting — lock acquisition order depends on hardware arbitration, not a queue.