Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Processes P1 and P2 use critical_flag in the ... Start Learning for Free
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
Correct answer is option 'C'. Can you explain this answer?
Verified Answer
Processes P1 and P2 use critical_flag in the following routine to achi...
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.
View all questions of this test
Most Upvoted Answer
Processes P1 and P2 use critical_flag in the following routine to achi...
Explanation:

Given Routine:
- The routine `get_exclusive_access()` checks if the `critical_flag` is FALSE.
- If the `critical_flag` is FALSE, it sets the `critical_flag` to TRUE, enters the `critical_region()`, and then sets the `critical_flag` back to FALSE.

(i) It is possible for both P1 and P2 to access critical_region concurrently:
- Since the routine uses a simple test-and-set mechanism to achieve mutual exclusion by setting and resetting the `critical_flag`, it ensures that only one process can enter the `critical_region` at a time.
- Therefore, it is not possible for both P1 and P2 to access the `critical_region` concurrently, satisfying statement (i).

(ii) This may lead to a deadlock:
- Deadlock occurs when two or more processes are waiting indefinitely for an event that can only be caused by one of the waiting processes.
- In the given routine, there is no occurrence of a situation where deadlock can happen as there is no possibility of circular waiting or resource holding.
- Therefore, statement (ii) is false as there is no deadlock scenario in the described routine.
Therefore, the correct answer is option (c) (i) is true and (ii) is false.
Free Test
Community Answer
Processes P1 and P2 use critical_flag in the following routine to achi...
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.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

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 trueb)Both (i) and (ii) are falsec)(i) is true and (ii) is falsed)Both (i) and (ii) are trueCorrect answer is option 'C'. Can you explain this answer?
Question Description
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 trueb)Both (i) and (ii) are falsec)(i) is true and (ii) is falsed)Both (i) and (ii) are trueCorrect answer is option 'C'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about 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 trueb)Both (i) and (ii) are falsec)(i) is true and (ii) is falsed)Both (i) and (ii) are trueCorrect answer is option 'C'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for 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 trueb)Both (i) and (ii) are falsec)(i) is true and (ii) is falsed)Both (i) and (ii) are trueCorrect answer is option 'C'. Can you explain this answer?.
Solutions for 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 trueb)Both (i) and (ii) are falsec)(i) is true and (ii) is falsed)Both (i) and (ii) are trueCorrect answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of 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 trueb)Both (i) and (ii) are falsec)(i) is true and (ii) is falsed)Both (i) and (ii) are trueCorrect answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of 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 trueb)Both (i) and (ii) are falsec)(i) is true and (ii) is falsed)Both (i) and (ii) are trueCorrect answer is option 'C'. Can you explain this answer?, a detailed solution for 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 trueb)Both (i) and (ii) are falsec)(i) is true and (ii) is falsed)Both (i) and (ii) are trueCorrect answer is option 'C'. Can you explain this answer? has been provided alongside types of 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 trueb)Both (i) and (ii) are falsec)(i) is true and (ii) is falsed)Both (i) and (ii) are trueCorrect answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice 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 trueb)Both (i) and (ii) are falsec)(i) is true and (ii) is falsed)Both (i) and (ii) are trueCorrect answer is option 'C'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev