recursive-mutex

When to use recursive mutex?

我的未来我决定 提交于 2019-11-26 11:59:56
问题 I understand recursive mutex allows mutex to be locked more than once without getting to a deadlock and should be unlocked the same number of times. But in what specific situations do you need to use a recursive mutex? I\'m looking for design/code-level situations. 回答1: For example when you have function that calls it recursively, and you want to get synchronized access to it: void foo() { ... mutex_acquire(); ... foo(); ... mutex_release(); } without a recursive mutex you would have to

Recursive Lock (Mutex) vs Non-Recursive Lock (Mutex)

安稳与你 提交于 2019-11-26 03:24:16
问题 POSIX allows mutexes to be recursive. That means the same thread can lock the same mutex twice and won\'t deadlock. Of course it also needs to unlock it twice, otherwise no other thread can obtain the mutex. Not all systems supporting pthreads also support recursive mutexes, but if they want to be POSIX conform, they have to. Other APIs (more high level APIs) also usually offer mutexes, often called Locks. Some systems/languages (e.g. Cocoa Objective-C) offer both, recursive and non recursive

Recursive Lock (Mutex) vs Non-Recursive Lock (Mutex)

若如初见. 提交于 2019-11-25 23:18:20
POSIX allows mutexes to be recursive. That means the same thread can lock the same mutex twice and won't deadlock. Of course it also needs to unlock it twice, otherwise no other thread can obtain the mutex. Not all systems supporting pthreads also support recursive mutexes, but if they want to be POSIX conform, they have to . Other APIs (more high level APIs) also usually offer mutexes, often called Locks. Some systems/languages (e.g. Cocoa Objective-C) offer both, recursive and non recursive mutexes. Some languages also only offer one or the other one. E.g. in Java mutexes are always