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
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.
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.