Write the \"reader\" part of this Java class.How will the structure of \"reader\
ID: 3920877 • Letter: W
Question
Write the "reader" part of this Java class.How will the structure of "reader" and "writer" be different?
public class ReaderWriter {
private int numberOfReaders = 0; //start from zero
private int numberOfWriters = 0; //start from zero
private void beforeWriting () {
numWriters++;
while ( numReaders != 0 ) wait ();//we can write when nobody is reading
}
private void doneWriting () {
numWriters--;
notifyAll ();
}
public synchronized void someWriteMethod (...) {//only one writer
beforeWriting ();
//do the writing
doneWriting ();
}
Explanation / Answer
//this is java code
//Reader writer problem,
if one process is writing no other process, can read it.
if at least one process is reading, no other process can write it
//Need any help please leave comment thanks.................
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.