Topic summary
Reentrant mutex

Synchronization primitive that can be locked multiple times by the same thread In computer science, the reentrant mutex (also known as a recursive mutex or recursive lock) is a synchronization primitive that may be locked multiple times by the same thread without causing a deadlock. While a thread that attempts to lock a standard (non-reentrant) mutex that it already holds would block indefinitely, this operation succeeds on a reentrant mutex. This is achieved by associating the mutex with the thread that owns it and maintaining a lock count. The owning thread can acquire the lock multiple times, incrementing the count each time. The lock is only released for other threads to acquire once the owning thread has unlocked it the same number of times it was acquired, bringing the count to zero. Motivation A reentrant mutex solves deadlocks that can occur when a function needs to acquire a lock that is already held by the same thread. This often happens in recursive code or when one function that acquires a lock calls another function that must acquire the same lock. Recursive mutexes solve the problem of non-reentrancy with regular mutexes: if a function that takes a lock and executes