4,386 views
4 votes
4 votes

Consider the following code to solve the critical section problem for two processes P0 and P1. Initially flag [i] contain false for i = 0 and 1.

Assume i refers to the current process Pi and refers the other process Pj. If two processes executing above code concurrently then which of the following satisfy the above solution?

A. Mutual exclusion and progress

B. Mutual exclusion and bounded wait

C. Progress

D. None of these

3 Answers

5 votes
5 votes

in this example, When Both are interested, then DEADLOCK happens

Deadlock ===> Mutual Exclusion ( Restriction is that entry section of each process should be same )

 

What about PROGRESS ? ( Below image is from 192 page of GALVIN book )

If dead lock happens, then process selection postponed to indefinitely ===> PROGRESS doesn't satisfied.

 

What about Bounded Waiting ? ( Below image is from 192 page of GALVIN book )

That means if Pi request for CS then Before Pi request grant, there should be a bound on how many times Pj can enter into CS

if DEADLOCK happens, no processes enter into CS, ( even Pj also can not enter) then how we talk about Bounded waiting ?

DEADLOCK ===> we can't judge about Bounded waiting.

For checking Bounded waiting take the possibilities which doesn't lead to DEADLOCK.

in this example, Bounded Waiting is satisfied.

1 votes
1 votes

The correct answer is it ensures Mutual exclusion and Bounded Waiting, but Fails at ensuring Progress.

If both processes are able to execute the statement  $ flag[i] = true$ before any process is able to enter the critical section then both processes will be stuck in while loop and no one will be able to enter critical section.

The number of times some process is able to enter critical section after the other process has made its request for critical section is clearly bounded. For example Process 0 tries to enter CS second time but will fail as Process 1 has made $flag[1] = true$.

How mutual exclusion is ensured is easy to prove by contradiction.

0 votes
0 votes

above are providing only MUTUAL exclusion and BOUNDED waiting but failed to provide Progresss.

Related questions

0 votes
0 votes
0 answers
1
Raj Singh 1 asked Jan 1, 2019
1,430 views
Many problems on gateoverflow asks whether the given code satisfies progress requirement of the solution for the critical section problem. Most of these code contain mult...
1 votes
1 votes
1 answer
3
Tuhin Dutta asked Oct 8, 2017
983 views
There are two threads which try to solve critical section problem using Test-And-Set instruction.Does the above code prevent deadlock? please provide reason to your answe...