Skip to content
uencoder

Lock

A lock is a synchronization primitive guaranteeing mutually exclusive access to shared resources, with types including mutexes, read-write locks, and spinlocks.

Purpose

Protect critical sections against data races — the core of shared-memory concurrency.

Mechanism

Mutex: exclusive access, only one thread holds it at a time. Read-write lock: many readers, single writer. Spinlock: busy-waits without sleeping. Reentrant lock: the same thread may acquire it repeatedly. Mind lock ordering to avoid deadlock.

Use cases

  • Concurrent synchronization
  • Critical section protection
  • Thread safety

Related terms

References