operating-systems concurrency

Definition

Race Condition

A race condition is a flaw in a concurrent system where the output depends on the uncontrollable timing of external events, such as OS scheduling of processes or threads. Influences outside the process’s control determine the final result, often leading to inconsistent outcomes.

Mitigation

Synchronisation

Prevent race conditions via mutual exclusion and synchronisation, ensuring controlled, deterministic access to shared resources.

Example

Concurrent Increment/Decrement

Shared variable a = 100:

  • Process A: Increment a by 100
  • Process B: Decrement a by 100

Sequential execution: a remains 100.
Interleaved execution: Result may be 200 or 0 depending on which process writes last.