Consider the following proposal to the readers and writers problem. Shared…

PYQ GATE 1987Modified — slightly modified from the official paper; see the solution

Consider the following proposal to the readers and writers problem. Shared integers aw, ar, rw, rr start at 0; semaphores reading and writing start at 0, and mutex starts at 1.

reader: P(mutex); ar:=ar+1; grantread; V(mutex); P(reading); read; P(mutex); rr:=rr-1; ar:=ar-1; grantwrite; V(mutex).
writer: P(mutex); aw:=aw+1; grantwrite; V(mutex); P(writing); write; P(mutex); rw:=rw-1; ar:=aw-1; grantread; V(mutex).
grantread: if aw=0 then while rr<ar do { rr:=rr+1; V(reading) }.
grantwrite: if rr=0 then while rw<aw do { rw:=rw+1; V(writing) }.

At a snapshot where exactly 12 readers are reading, exactly one writer is waiting, no other process is active, all 12 reader permits have been consumed, and none has exited, give the shared-variable values and semaphore states. Can readers starve a waiting writer? Can writers starve readers? Explain in two sentences why the proposal is incorrect.

Sign up free to check your answer

Sign up free

Explore the full course: Zero To Hero

Loading lesson…