DELAPARRA
Index
Color
NL
Category: Core glossary

Mutex (Mutual Exclusion)

Explained by Updated

What is Mutex (Mutual Exclusion)?

Mutex (Mutual Exclusion): A synchronisation primitive that prevents multiple threads from accessing a shared resource simultaneously, avoiding race conditions. A mutex, short for mutual exclusion, makes sure only one thread or process works on a shared resource at a time. Others that want it must wait until it is released. Without it, two processes can read the same value, both change it and both write it back, losing one of the changes. A mutex turns that critical section into a single-file queue.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Mutex (Mutual Exclusion)

What should you keep in mind with Mutex (Mutual Exclusion)?

In web applications, the threads are often separate requests or queue workers, possibly on different servers. Then you need a lock everyone can see, such as a database row lock or a cache lock. Laravel's Cache::lock('import') is a simple way to stop two imports running at once. Always release locks, also when errors occur, and set a timeout so a crashed process cannot block everyone forever.

At a glance

CategoryCore glossary
Explained by
Updated

More Core glossary terms

All terms starting with M

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.