Question

In: Computer Science

As long as there are fewer than three processes using the resource, new processes can start using it right away.

Consider a sharable resource with the following characteristics: 

(1) As long as there are fewer than three processes using the resource, new processes can start using it right away. 

(2) Once there are three processes using the resource, all three must leave before any new processes can begin using it. We realize that counters are needed to keep track of how many processes are waiting and active, and that these counters are themselves shared resources that must be protected with mutual exclusion. So we might create the following solution:

semaphore mutex = 1, block = 0; int active = 0, waiting 1 /* share variables: semaphores, */ /* counters, and * / /* state information */ 2 = 0; 3 boolean must wait = false; 4 semwait (mutex); if (must_wait) { /* Enter the mutual exclusion */ 6 /*

 

The solution appears to do everything right: All accesses to the shared variables are protected by mutual exclusion, processes do not block themselves while in the mutual exclusion, new processes are prevented from using the resource if there are (or were) three active users, and the last process to depart unblocks up to three waiting processes.

a. The program is nevertheless incorrect. Explain why.

b. Suppose we change the if in line 6 to a while. Does this solve any problem in the program? Do any difficulties remain?

 

Solutions

Expert Solution

This problem and the next two are based on examples in; Reek, K. "Design Patterns for Semaphores." ACM SIGCSE’04, March 2004. 

 

 

a.         

We quote the explanation in Reek's paper. There are two problems. First, because unblocked processes must reenter the mutual exclusion (line 10) there is a chance that newly arriving processes (at line 5) will beat them into the critical section. Second, there is a time delay between when the waiting processes are unblocked and when they resume execution and update the counters. The waiting processes must be accounted for as soon as they are unblocked (because they might resume execution at any time), but it may be some time before the processes actually do resume and update the counters to reflect this. To illustrate, consider the case where three processes are blocked at line 9. The last active process will unblock them (lines 25-28) as it departs. But there is no way to predict when these processes will resume executing and update the counters to reflect the fact that they have become active. If a new process reaches line 6 before the unblocked ones resume, the new one should be blocked. But the status variables have not yet been updated so the new process will gain access to the resource. When the unblocked ones eventually resume execution, they will also begin accessing the resource. The solution has failed because it has allowed four processes to access the resource together. 

 

b.         

This forces unblocked processes to recheck whether they can begin using the resource. But this solution is more prone to starvation because it encourages new arrivals to “cut in `line” ahead of those that were already waiting.


This forces unblocked processes to recheck whether they can begin using the resource. But this solution is more prone to starvation because it encourages new arrivals to “cut in `line” ahead of those that were already waiting.

Related Solutions

Which type of risk that is associated with investments can be diversified away under the right...
Which type of risk that is associated with investments can be diversified away under the right conditions?
When you take your first job, you decide to start saving right away for your retirement....
When you take your first job, you decide to start saving right away for your retirement. You put $5,000 per year into a saving plan, which interest rate 10% per year. Five years later, you move to another job and stop making contributions to the saving plan. If the first plan continued to earn interest for another 35 years, determine the future worth in year 40. $81,954 $89,154 $857,840 $859,840
USING EXCEL: Consider the probability that no fewer than 75 out of 111 houses will lose...
USING EXCEL: Consider the probability that no fewer than 75 out of 111 houses will lose power once a year. Assume the probability that a given house will lose power once a year is 98% Specify whether the normal curve can be used as an approximation to the binomial probability by verifying the necessary conditions. PLEASE USE EXCEL AND SHOW EXCEL FORMULAS USED FOR SOLUTION. THANK YOU!!
Do left handed starting pitchers pitch fewer innings per game on average than right handed starting...
Do left handed starting pitchers pitch fewer innings per game on average than right handed starting pitchers? A researcher looked at eleven randomly selected left handed starting pitchers' games and eleven randomly selected right handed pitchers' games. The table below shows the results. Left:  6 6 8 6 5 7 5 7 5 5 Right:  6 8 7 7 7 6 8 6 8 7 Assume that both populations follow a normal distribution. What can be concluded at the the αα =...
Justice & fairness - MOHR can start an ombudsman facility and the Right to Enquire.
Justice & fairness - MOHR can start an ombudsman facility and the Right to Enquire. Thus, bad practices of the company can come out, if a person applies to know about it. It is mostly related to governmental organizations and their spending. Also, the ombudsman facility would allow people to put their grievances in the company or let the world understand about bad practices of the company. It should keep the identity of the whistleblower as confidential. The ombudsman service...
Describe the phases and processes to start-up a new sustainable business and the risks that may...
Describe the phases and processes to start-up a new sustainable business and the risks that may be involved at each stage?
please show me or tell me a trick, on how can i tell right away when...
please show me or tell me a trick, on how can i tell right away when a characteristics equation(system) is 1)overdamped 2)underdamped 3)critically damped 4) nonlinear show each an example write neatly!!!!!
Q2) A drug manufacturer claims that fewer than 10% of patients who take its new drug...
Q2) A drug manufacturer claims that fewer than 10% of patients who take its new drug for treating Alzheimer’s disease will experience nausea. In a random sample of 500 patients, 47 experienced nausea. Perform a significance test at the 5% significance level to test this claim. (a) State the null and alternative hypothesis. (b) Calculate the test statistic. (c) Calculate the p-value. Round to 4 decimal places (d) Make a decision at the 0. 05 significance level to reject Ho...
There are three ways that radiating light can interact with matter. (a)List those  processes and Illustrate each processes using simple two level&nbs
There are three ways that radiating light can interact with matter. (a)List those  processes and Illustrate each processes using simple two level system. (b) which  one is the basis of lasing? (c) In that (lasing) process, explain why emitted photon  has the same phase, polarization and direction as the exciting photon.
There are three ways that radiating light can interact with matter. (a)List those  processes and Illustrate each processes using simple two level&nbs
There are three ways that radiating light can interact with matter. (a)List those  processes and Illustrate each processes using simple two level system. (b) which  one is the basis of lasing? (c) In that (lasing) process, explain why emitted photon  has the same phase, polarization and direction as the exciting photon.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT