Consider the following code for N (>1) readers and a single writer.
// Global Variables, initialized once:
int readcount = 0;
boolean readOK = true;
boolean writeOK = false;
Readers: Writer:
while (true) { while (true) {
readcount++; while (readOK) {} // empty loop body
if (readcount == 1) { writeOK = true;
while (writeOK) {} // empty loop body
readOK = true; // write data section
}
else writeOK = false;
while (!readOK) {} // empty loop body }
// read data section
readcount--;
if (readcount == 0)
readOK = false;
}
Answer the following questions YES/NO, with a description of the sequence of events leading to the described situation. There are good, brief explanations that will be acceptable. Note: in all cases, the CPU scheduler will give each process repeated access to the CPU.
Is it possible (perhaps after an initial period) to get into a situation such that:
a) data is read AND written at the same time (i.e. no mutual exclusion)?
b) ONLY data is read (i.e. not fair to the writer, hence starvation)?
c) ONLY data is written (i.e. not fair to the readers, hence starvation)?
d) NO data is read or written (i.e. no progress)?