Glossary · Automation software engineering and architecture
Mutex
Also known as: Mutual exclusion lock, Lock
German: Mutex
In concurrent programming, a mutex is a synchronization object that only one thread can hold at a time, used to protect a critical section or shared resource from simultaneous access.
- Software engineering
In one sentence
A mutex is a lock that only one thread can hold at a time, protecting a shared resource or critical section from simultaneous access.
Example
The logging task and the communication task both write to the same diagnostic buffer, so each takes the buffer's mutex before writing and releases it afterward.
How it applies
- Engineering: A mutex has an owner: the thread that locks it must unlock it. Holding it as briefly as possible limits blocking; always acquiring several mutexes in the same order avoids Deadlock.
- Real-time systems: In an RTOS, a mutex usually supports Priority inheritance to limit Priority inversion, and blocking time on mutexes is part of the timing analysis.
- Documentation: Software design documents should list shared resources and the mutex protecting each, which helps reviewers check Thread safety.
Mutex vs. semaphore
A mutex is owned and allows exactly one holder. A counting Semaphore has no owner and allows up to N holders or is used for signaling between tasks. A binary semaphore resembles a mutex but usually lacks ownership and priority inheritance.