I have a mutex library, and am trying to implement a write-preferring lock. I am looking at this example:
https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock
I understand the read-preferring lock, but I don't understand the write-preferring lock. Can someone explain how to implement that?
Specifically, I don't understand this part:
While w:
wait c, m
I also don't understand if the flag w
is universal, or just a different flag per process. I assume it's the former.
For example, here we see the algorithm for getting a read-lock:
Lock m (blocking).
While (w or r > 0):
wait c, m
Set w to true.
Unlock m.
but what does wait c, m
mean?
It can't mean waiting to get a lock on both c
and m
, because we already locked m
in step 1.
And also, for Set w to true
- does that mean w
has to be set to true in all processes or just this process?