Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Real Time Database Systems Architecture And Techniques

Authors: Kam-Yiu Lam ,Tei-Wei Kuo

1st Edition

1475784023, 978-1475784022

More Books

Students also viewed these Databases questions

Question

Does it use a maximum of two typefaces or fonts?

Answered: 1 week ago