Mutex
A mutex (short for "mutual exclusion") is a programming tool used to manage access to shared resources in a computer program. When multiple threads or processes try to access the same resource, a mutex ensures that only one can do so at a time. This prevents conflicts and data corruption, making programs safer and more reliable.
When a thread wants to use a shared resource, it must first "lock" the mutex. If another thread tries to lock the same mutex while it's already locked, it will have to wait until the first thread "unlocks" it. This simple mechanism helps maintain order and consistency in multi-threaded environments, such as those found in operating systems and software applications.