GATE Computer Science (CS) 2021 Shift 2 Solved Paper
© examsiri.com
Question : 52 of 65
Marks:
+1,
-0
Consider the following multi-threaded code segment (in a mix of C and pseudocode), invoked by two processes P1 and P2, and each of the processes spawns two threads T1 and T2:
Which of the following statement(s) is/are correct ?
int x = 0; // global
Lock L1; // global
main() {
create a thread to execute foo(); // Thread T1
create a thread to execute foo(); // Thread T2
wait for the two threads to finish execution;
print (x);}
foo() {
int y = 0;
Acquire L1;
x = x + 1;
y = y + 1;
Release L1;
print (y); }Which of the following statement(s) is/are correct ?
Go to Question: