Question: 1 . The following reader - writer algorithm works for multiple readers and a single writer. It allows reading of the shared variables x 1

1. The following reader-writer algorithm works for multiple readers and a
single writer. It allows reading of the shared variables x1 and x2 into local
variables d1 and d2 without locking, thus not blocking the writer.
Before writing to the shared variables x1 and x2, 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 (i.e., 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.
Non-blocking reader-writer
integer c, x1, x20
reader writer
integer c0, d1, d2 integer d1, d2
loop forever loop forever
p1: repeat q1: d1 get()
p2: repeat q2: d2 get()
p3: c0 c q3: c c+1
p4: until (c0 mod 2=0) q4: x1 d1
p5: d1 x1 q5: x2 d2
p6: d2 x2 q6: c c+1
p7: until (c0= c) q7:
p8: use(d1,d2) q8:
(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, i.e., 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!