Open In App

GATE | Gate IT 2007 | Question 10

Like Article
Like
Save
Share
Report

Processes P1 and P2 use critical_flag in the following routine to achieve mutual exclusion. Assume that critical_flag is initialized to FALSE in the main program.

get_exclusive_access ( )
{
if (critical _flag == FALSE) {
critical_flag = TRUE ;
critical_region () ;
critical_flag = FALSE;
}
}

Consider the following statements.
i. It is possible for both P1 and P2 to access critical_region concurrently.
ii. This may lead to a deadlock.

Which of the following holds?
(A) (i) is false and (ii) is true
(B) Both (i) and (ii) are false
(C) (i) is true and (ii) is false
(D) Both (i) and (ii) are true


Answer: (C)

Explanation:

Say P1 starts first and executes statement 1, after that system context switches to P2 (before executing statement 2), and it enters inside if statement, since the flag is still false.
So now both processes are in critical section!! so (i) is true.. (ii) is false
By no way it happens that flag is true and no process’ are inside the if clause, if someone enters the critical section, it will definitely make flag = false. So no deadlock.


Quiz of this Question


Last Updated : 14 Feb, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads