Question: 13. How could you change the program in Figure 3 to avoid a deadlock? [2 points] 0) Semaphore sem1, sem2, sem3; 1) 2) int

 13. How could you change the program in Figure 3 to avoid a deadlock? [2 points] 0) Semaphore sem1, sem2, 

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);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To avoid a deadlock in the program shown we must ensure that semaphores are always acquired in the s... View full answer

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 Programming Questions!