Question
1.Let A and B be two semaphores initialized to 1, whether this following code has problem, if so, which problem and explain your answer P
1.Let A and B be two semaphores initialized to 1, whether this following code has problem, if so, which problem and explain your answer
P0 P1
wait(A); wait(B);
wait(B); wait(A);
signal(A); signal(B);
signal(B); signal(A);
2.Philosophers spend their lives thinking and eating . These Philosophers dont interact with their neighbors, occasionally try to pick up 2 chopsticks (one at a time) to eat from bowl and they need both to eat, then release both when done
In the case of 5 philosophers, Semaphore chopstick [5] initialized to 1
Does the following codes have problem? If so, which kind(s) problem(s)? How to deal with the problem(s)?
do {
wait (chopstick[i] );
wait (chopStick[ (i + 1) % 5] );
// eat
signal (chopstick[i] );
signal (chopstick[ (i + 1) % 5] );
// think
} while (TRUE);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started