Question
Please provide an answer for this with detailed explanation. 3) Consider the Readers/Writers problem where any number of readers can examine a file, but only
Please provide an answer for this with detailed explanation.
3) Consider the Readers/Writers problem where any number of readers can examine a file, but only one writer at a time can update the file. A writer is only allowed access when there are no active readers. Consider the following code as a potential solution. The common variables are the two semaphores (both initially 1) and the integer variable readcount (initially 0).
semaphore wrt=1,mutex=1;
readcount=0;
writer() {
1: wait(wrt); //writing is done
2: signal(wrt);
}
reader() {
3: wait(mutex);
4: readcount++;
5: if(readcount==1)wait(wrt);
6: signal(mutex); //Do the Reading
7: wait(mutex);
8: readcount--;
9: if(readcount==0)signal(wrt);
10: signal(mutex);
}
In each of the following, your answer should be either :
i) has no significant effect or ii) is needed for a correct solution or iii) makes for an incorrect solution Explain your choice. Note that each question is independent. That is, it assumes the original code above.
a) What is the effect of swapping lines 5 and 6?
b) What is the effect of omitting lines 7 and 10
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started