Q8a
MCQMarks unknownConsider the following proposal to the "readers and writers problem." Shared variables and semaphores: aw, ar, rw, rr : interger; mutex, reading, writing: semaphore: initial values of variables and states of semaphores: ar=rr=aw=rw=0 reading_value = writing_value = 0 mutex_value = 1. Process writer; Process reader; begin begin while true do repeat begin P(mutex); P(mutex); ar := ar+1; aw := aw + 1; grantread; grantwrite; V(mutex); V(mutex); P(reading); P(writing); read; Write; P(mutex); P(mutex); rr := rr - 1; rw := rw - 1; ar := ar - 1; ar := aw - 1; grantwrite; grantread; V(mutex); V(mutex); other-work; other-work; until false end end. end. Procedure grantread; begin if aw = 0 then while (rr < ar) do begin rr := rr + 1; V (reading) end end; Procedure grantwrite; begin if rr = 0 then while (rw < aw) do begin rw := rw + 1; V (writing) end end;
Loading…