Reputation: 1
I am confused about the reentrant lock and mutual exclusion if a thread can reacquire lock multiple times doesn't it violet mutual exclusion because other thread also wants to acquire the lock?
i know that reentrant locks are used for recursive function so that it doesn't enter deadlock when doing recursion but how does it ensures mutual exclusion?
Upvotes: -1
Views: 39
Reputation: 21667
The answer to your question depends upon the nature of the operating system. In an interrupt driven operating system (ie supports software interrupts) allowing the same thread to acquire a reentrant lock does not guarentee mutual exclusion. If threads execute exclusively sequentially then it does have mutual exclusion.
In the former case:
Main thread code Locks Resource Main thread code starts to manipulate Resource. Thread interrupt executes Thread interrupt locks Resource. Thread Interrupt manipulates resource thread Interrupt unlock resource Main thread code finishes manipulting Resource Main thread code unlocks Resource
Resource is in an indeterminant state.
Upvotes: 0