The Readers / Writers Problem
Writing is exclusive.
Several readers can read together.
Readers have priority over writers.
wait( wrt );
…
writing is performed
…
signal( wrt );
wait( mutex );
rcount := rcount + 1;
if (rcount = 1 ) then wait( wrt );
signal( mutex );
…
reading is performed
…
wait( mutex );
rcount := rcount - 1;
if (rcount = 0 ) then
signal( wrt );
signal( mutex );
Writer
Reader
Initialization
semaphores: mutex = 1;
wrt = 1;
integer : rcount = 0;
Previous slide
Next slide
Back to first slide
View graphic version