# Mutex

Last edited: 2026-02-05

Mutex

A mutex is a lock on some shared operation between threads . For example accessing shared memory. To do the operation you must obtain the mutex (if some other thread has the mutex you enter a wait state). The mutex is just a data structure consisting of at least:

  • Status of the mutex,
  • Current mutex owner, and
  • List of threads waiting on the mutex.

Birrells original API used a context manager syntax but common APIs use an lock and unlock command. The code in the context manager or between the lock and unlock commands is called the critical section.