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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post by answerhappygod »

13 How Could You Change The Program In Figure 3 To Avoid A Deadlock 2 Points 0 Semaphore Semi Sem2 Sem3 1 2 Int 1
13 How Could You Change The Program In Figure 3 To Avoid A Deadlock 2 Points 0 Semaphore Semi Sem2 Sem3 1 2 Int 1 (75.45 KiB) Viewed 26 times
13. How could you change the program in Figure 3 to avoid a deadlock? [2 points] 0) Semaphore semi, sem2, sem3; 1) 2 int main() { initializeSempahore( sem1, 1); // Used as a binary semaphore 14) initializeSempahore (sem2, 1); // Used as a binary semaphore 5) initializeSempahore (sem3, 1); // Used as a binary semaphore I7) // Create and start threads 18 thread t1(threadRunnerA); 9) thread t2(threadRunnerB); 10) // ... Other code 11) return 0; 12) } 13 14) void threadRunnerA() { // Function executing as a thread (15) wait(sem1); 16) wait (sem2); 17) 18) // Do some work ... 19) signal (sem 1); 120) wait (sem3); 21) // Do some more work ... 22) 23) signal(sem2); (24) signal( sem3); 25) } 126) 27) void threadRunnerB() { // Function executing as a thread 28) wait(sem1); 29) wait( sem3); 30) 31) // Do some work 32) signal(sem1); 133) wait (sem2); 34) 35) // Do some more work ... signal(sem2); 37) signal(sem3); 38) } Figure 3: Program listing 3 36)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply