Skip to content

Latest commit

 

History

History
22 lines (12 loc) · 916 Bytes

File metadata and controls

22 lines (12 loc) · 916 Bytes

MUTEX

A mutex (mutual exclusion) is a synchronization primitive that ensures only one thread at a time can access a shared resource or critical section. A thread locks the mutex before accessing the resource and unlocks it after, preventing race conditions.

Race Condition

Happens when multiple thread access shared resource concurrently and result depends on the order of execution.

  • protect the shared data with locks or use atomics for simpler types

Deadlock

Happens when two or more thread wait forever for each others lock.

  • lock and unlock resources in order, best to use modern lock guards over mutexes or choose lock free designs

Race condition is logic/behaviour related issue while deadlock is resource acquisition related

Conditional Variable

A condition variable lets a thread sleep efficiently until a condition becomes true, instead of busy-waiting.