...
Engineering-Mathematics
October 3, 2023
GATE 2022
October 3, 2023
Engineering-Mathematics
October 3, 2023
GATE 2022
October 3, 2023

Operating-Systems

Question 18

Each of a set of n processes executes the following code using two semaphores a and b initialized to 1 and 0, respectively. Assume that count is a shared variable initialized to 0 and not used in CODE SECTION P.

wait (a); count = count+1;
if (count==n) signal (b);
signal (a); wait (b); signal (b);

What does the code achieve?

A
It ensures that all processes execute CODE SECTION P mutually exclusively.
B
It ensures that at most two processes are in CODE SECTION Q at any time.
C
It ensures that no process executes CODE SECTION Q before every process has finished CODE SECTION P.
D
It ensures that at most n-1 processes are in CODE SECTION P at any time.
Question 18 Explanation: 
The wait(a) ensures that the count value is correctly incremented (no race condition) if(count==n) signal (b); // This signal(b) statement is executed by the last (nth) process only. Rest of the n-1 processes are blocked on wait(b). Once the nth process makes signal(b) then the rest of the processes can proceed and enter Code section Q.
Correct Answer: C
Question 18 Explanation: 
The wait(a) ensures that the count value is correctly incremented (no race condition) if(count==n) signal (b); // This signal(b) statement is executed by the last (nth) process only. Rest of the n-1 processes are blocked on wait(b). Once the nth process makes signal(b) then the rest of the processes can proceed and enter Code section Q.
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!