operating-systems concurrency

Definition

Mutual Exclusion

Mutual exclusion is the property that at most one process or thread can execute its critical section or access a shared resource at any given time.

Mutual exclusion prevents race conditions and ensures data consistency. It is orthogonal to condition synchronisation, which concerns ordering of events rather than exclusivity.

Requirements

Any correct mutual exclusion mechanism must satisfy:

Mutual Exclusion

At most one process executes in its critical section at any time.

Progress

If no process is in its critical section and some processes wish to enter, the selection of the next process to enter cannot be postponed indefinitely.

Bounded Waiting

A process waiting to enter its critical section will do so within a bounded number of turns (no starvation).

Mechanisms

Modern operating systems provide several primitives:

MechanismDescription
MutexLow-level lock with ownership semantics
SemaphoreCounter-based signalling primitive
MonitorHigh-level construct with condition variables
Message PassingExclusion via ownership transfer

Priority Schemes

Basic Priority via Semaphore Wrapper

Processes of type have priority over type . An additional semaphore restricts entry: while multiple processes may wait on resource semaphore , at most one process waits on ; others block on .

Semaphore s = 1      // resource lock
Semaphore x = 1      // priority control for B

Void processA()
    s.wait()
    /* --- Critical Section --- */
    s.signal()

Void processB()
    x.wait()
        s.wait()
        /* --- Critical Section --- */
        s.signal()
    x.signal()

Strict Priority via Counter

A counter tracks waiting processes. The first to arrive blocks all processes; the last to leave releases them. No enters if any is waiting. This mirrors writer-priority reader-writer logic.