[NSWI004] Question about lock in 08-memory-models-graded
Petr Tuma
petr.tuma at d3s.mff.cuni.cz
Thu Nov 26 08:51:29 CET 2020
Hello,
> I have a question about Q3 in 08-memory-models-graded. What is meant by the recursive_lock/unlock methods? Should we assume the lock is implemented as some kind of reetrant mutex (as described in https://en.wikipedia.org/wiki/Reentrant_mutex <https://en.wikipedia.org/wiki/Reentrant_mutex>)?
Yes. Apart from the Wikipedia entry, this was also mentioned in the discussion for lecture 07:
- A recursive lock is a lock that remembers how many times it was locked
- Repeated locking only possible from the same thread
- Must be unlocked as many times as was locked
- Quite useful when nesting code with locks
The same terminology is used for example with POSIX thread locks, see also `man pthread_mutex_lock`.
Finally, in this particular question, it does not really matter, no recursion related behavior is triggered.
Petr
More information about the NSWI004
mailing list