Reader/Writer with Semaphores: Take 2
SharedLock::AcquireRead() {
rblock.P();
rmx.P();
if (first reader)
wsem.P();
rmx.V();
rblock.V();
}
SharedLock::ReleaseRead() {
rmx.P();
if (last reader)
wsem.V();
rmx.V();
}
SharedLock::AcquireWrite() {
wmx.P();
if (first writer)
rblock.P();
wmx.V();
wsem.P();
}
SharedLock::ReleaseWrite() {
wsem.V();
wmx.P();
if (last writer)
rblock.V();
wmx.V();
}
This is a bit difficult to read, so let’s simplify it....
Previous slide
Next slide
Back to first slide
View graphic version