Computers and Technology, 21.04.2022 02:30 bthakkar25
Consider a sharable resource with the following characteristics: 1) as long as there are fewer than three processes using the resource, new processes, 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:
1 semaphore mutex =1, block =0;
2 int active=0; waiting =0;
3 boolean must_wait=false;
4
5 semWait(mutex);
6 if(must_wait) {
7 ++waiting;
8 semSignal(mutex);
9 semWait(block);
10 semWait(mutex);
11 --waiting;
12 }
13 ++active;
14 must_wait = active ==3;
15 semSignal(mutex);
16
17 /*critical section*/
18 semWait(mutex);
19 --active;
20 if(active == 0) {
21 int n;
22 if (waiting < 3) n=waiting;
23 else n=3;
24 while (n>0) {
25 semSignal(block);
26 --n;
27 }
28 must_wait=false;
29 }
30 semSignal(mutex);
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.
The program is nevertheless incorrect. Explain why.
Suppose we change the if in line 6 to a while. Does this solve any problem in the program? Do any difficulties remain?
Answers: 2
Computers and Technology, 22.06.2019 03:10
Write a program that begins by reading in a series of positive integers on a single line of input and then computes and prints the product of those integers. integers are accepted and multiplied until the user enters an integer less than 1. this final number is not part of the product. then, the program prints the product. if the first entered number is negative or 0, the program must print βbad input.β and terminate immediately. next, the program determines and prints the prime factorization of the product, listing the factors in increasing order. if a prime number is not a factor of the product, then it must not appear in the factorization. sample runs are given below. note that if the power of a prime is 1, then that 1 must appear in t
Answers: 3
Computers and Technology, 23.06.2019 18:00
What can a word user do with the customize ribbon dialog box? check all that apply. minimize the ribbon add a new tab to the ribbon remove a group from a tab add a group to a tab choose which styles appear choose which fonts appear choose tools to appear in a group
Answers: 1
Computers and Technology, 23.06.2019 21:20
In microsoft word, when you highlight existing text you want to replace, you're in a. advanced mode. b. automatic mode. c. basic mode. d. typeover mode
Answers: 1
Consider a sharable resource with the following characteristics: 1) as long as there are fewer than...
Mathematics, 17.09.2020 16:01
English, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01
Chemistry, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01
Mathematics, 17.09.2020 16:01