I need some help understanding the implementation of the one-writer many-readers problem shown below as I am new to this concept:
I have a rough idea that there will be starvation/deadlock among the readers as there is one writer that multiple readers are trying to access at once. Can anyone please provide some further insight regarding the problems with the implementation of this situation?
I am not looking for any coding, that was just the sample code (pseudocode) I am working with. I am looking for the problem of the implementation. Upon further research I have assumed the following (based on the line:
if readcount == 1 then semWait(wrt); :
- There is one writer and many readers
- The readers have priority over the writers
- The possible problem: The writers cannot write until the reader has finished reading therefore starvation occurs
However upon re-evaluation of the code I have also assumed the following based on the lines:
semWait(mutex); readcount := readcount - 1; if readcount == 0 then up semSignal(mutex);
Could I not also say that only one reader may read at a time therefore the other readers will be starved?
Therefore would either of these be the correct way of interpreting the coding to the problem is of the implementation or would I be wrong?