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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!