Question: 1 . The following reader - writer algorithm works for multiple readers and a single writer. It allows reading of the shared variables x 1
The following readerwriter algorithm works for multiple readers and a
single writer. It allows reading of the shared variables x and x into local
variables d and d without locking, thus not blocking the writer.
Before writing to the shared variables x and x the writer increments a
counter c It then proceeds to write to the variables, and finally increments
c again. The two increments of c ensure that it is odd when the process
is writing to the variables, and even otherwise. Hence, when a reader
wishes to read the shared variables, it waits in a loop until c is even before
reading them. Also, before returning it checks that the value of c has not
changed ie another write has not begun If it has changed, the process
starts over. This ensures the pair of values read corresponds to a single
occurrence of a write.
Nonblocking readerwriter
integer c x x
reader writer
integer c d d integer d d
loop forever loop forever
p: repeat q: d get
p: repeat q: d get
p: c c q: c c
p: until c mod q: x d
p: d x q: x d
p: d x q: c c
p: until c c q:
p: usedd q:
a Describe a scenario showing that the algorithm is not correct when
there is more than one writer. Explain how you could modify the
algorithm to allow multiple writers by placing standard, ie nonlanguage specific, synchronisation mechanisms in the code. Justify
that your modification ensures that no writer process is ever
blocked unnecessarily.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
