(a) Fill in the boxes below to get a solution for the readers-writers problem,…
PYQ GATE 2000
(a) Fill in the boxes below to get a solution for the readers-writers problem, using a single binary semaphore, mutex (initialized to 1) and busy waiting. Write the box numbers (1, 2 and 3), and their contents in your answer book.
int R = 0, W = 0;
Reader() {
L1: wait(mutex);
if (W == 0) {
R = R + 1;
_______(1)
} else {
_______(2)
goto L1;
}
/* do the read */
wait(mutex);
R = R − 1;
signal(mutex);
}
Writer() {
L2: wait(mutex);
if (_______(3)) {
signal(mutex);
goto L2;
}
W = 1;
signal(mutex);
/* do the write */
wait(mutex);
W = 0;
signal(mutex);
}(b) Can the above solution lead to starvation of writers?
Sign up free to check your answer
Sign up freeLoading lesson…

