13. How could you change the program in Figure 3 to avoid a deadlock? [2 points]...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
13. How could you change the program in Figure 3 to avoid a deadlock? [2 points] 0) Semaphore sem1, sem2, sem3; 1) 2) int main() { initializeSempahore (sem1, 1); // Used as a binary semaphore initializeSempahore (sem2, 1); // Used as a binary semaphore initializeSempahore (sem3, 1); // Used as a binary semaphore 4) 5) 7) 9) 10) 11) 12) } // Create and start threads thread t1 (threadRunnerA); thread t2 (threadRunnerB); // ... Other code return 0; 13) 14) void threadRunnerA() { // Function executing as a thread 15) 16) 17) 18) 19) 120) 21) 22) 23) 24) 25) } 26) wait (sem1); wait (sem2); // Do some work signal (sem1); wait (sem3); // Do some more work... signal (sem2); signal (sem3); 27) void threadRunnerB () { // Function executing as a thread 28) wait (sem1); 29) wait (sem3); 30) 31) 32) signal (sem1); 33) wait (sem2); 34) 35) 36) 37) 38)} Figure 3: Program listing 3 // Do some work. III // Do some more work... signal (sem2); signal (sem3); 13. How could you change the program in Figure 3 to avoid a deadlock? [2 points] 0) Semaphore sem1, sem2, sem3; 1) 2) int main() { initializeSempahore (sem1, 1); // Used as a binary semaphore initializeSempahore (sem2, 1); // Used as a binary semaphore initializeSempahore (sem3, 1); // Used as a binary semaphore 4) 5) 7) 9) 10) 11) 12) } // Create and start threads thread t1 (threadRunnerA); thread t2 (threadRunnerB); // ... Other code return 0; 13) 14) void threadRunnerA() { // Function executing as a thread 15) 16) 17) 18) 19) 120) 21) 22) 23) 24) 25) } 26) wait (sem1); wait (sem2); // Do some work signal (sem1); wait (sem3); // Do some more work... signal (sem2); signal (sem3); 27) void threadRunnerB () { // Function executing as a thread 28) wait (sem1); 29) wait (sem3); 30) 31) 32) signal (sem1); 33) wait (sem2); 34) 35) 36) 37) 38)} Figure 3: Program listing 3 // Do some work. III // Do some more work... signal (sem2); signal (sem3);
Expert Answer:
Answer rating: 100% (QA)
To avoid a deadlock in the program shown we must ensure that semaphores are always acquired in the s... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Historical returns for the past three years for Stock B and the stock market portfolio are Stock B: 30 percent, 0 percent, 30 percent; market portfolio : 18 percent, 20 percent, 28 percent. The...
-
Which of the following represents the GREATEST risk created by a reciprocal agreement for disaster recovery made between two companies? A. Developments may result in hardware and software...
-
State or local government entities can engage in governmental activities as well as business-type activities. Provide two examples of each activity type. Discuss how and why accounting and financial...
-
Barber Technologies designs and develops software to be used for the management of inventory by both retailers and manufacturing firms. Over the past three years, the company has experienced...
-
Consider the derivation of Equation (4.5) for the sample size of a two-sample z-test with known variance and equal allocation. a. Identify terms in Equation (4.2) that are smaller than $\alpha / 2$...
-
Administrative theorists concluded many decades ago that the most effective organizations have a narrow span of control. Yet todays top-performing manufacturing firms have a wide span of control. Why...
-
Journalize the nine adjusting entries that the company made on December 3 1 , current year. TINKER CORPORATION TRIAL BALANCES DECEMBER 31, CURRENT YEAR Unadjusted Adjusted Debit Credit Debit Credit...
-
(a) A homogeneous solid body of arbitrary shape is initially at temperature T, throughout. At t = 0 it is immersed in a fluid medium of temperature T. Let L be a characteristic length in the solid....
-
Faith enjoys classical CDs and travel books and spends N$75 a month on them. Table 2 shows the utility she gets from each good. Table 2 Utility schedule Total utility classical CDS (a) (b) (c) 0 90...
-
What do you think explains the placebo effect?
-
Trace the path of air as it moves to the alveoli.
-
What happens to food while it is in the stomach?
-
The pumping of the heart does most of the work that is required to move blood around the body. How do your voluntary movements contribute?
-
What is the function of the loop of Henle?
-
Book: El Deafo By: Cece Bell I need the Ten Steps for Reviewing Childrens Books. 1. Check the illustrations 2. Check the story line 3. Look at the lifestyles 4. Weigh the relationships between people...
-
MgO prevents premature evaporation of Al in a furnace by maintaining the aluminum as Al2O3. Another type of matrix modifier prevents loss of signal from the atom X that readily forms the molecular...
-
In this exercise, you use the Employee class from Pencil and Paper Exercise 4 to create an Employee object. Follow the instructions for starting C++ and viewing the TryThis7.cpp file, which is...
-
A group of related fields that contain all of the data about a specific person, place, or thing is called a _____________________. a. Field b. File c. Record d. None of the above
-
Create a program that a teacher can use to enter the midterm and final test scores for any number of students. Each test is worth 200 points. The program should display each students grade, which is...
-
A driver holds his hands on opposite sides of the 35-cm-diameter steering wheel in a modern sports car. A torque of 4.5 N m is required to turn the wheel. If the driver applies an equal force on...
-
A gymnast on the uneven parallel bars is at rest, tipped at a 45 angle from the vertical. The distance from her hands to her feet is 1.8 m. If we model her body as having a uniform cross section and...
-
The engine in a small airplane is specified to have a torque of 500 N m. This engine drives a 2.0-m-long, 40 kg single-blade propeller. On startup, how long does it take the propeller to reach 2000...
Study smarter with the SolutionInn App