Skip to content

Beta · Data may be lost.Your data may be reset or lost.

GateBrew
← GATE CSE 2021 Set 2
Questions

Q42

MSQ2 marksOperating systems

Consider the following multi-threaded code segment (in a mix of C and pseudo-code), invoked by two processes P1P_1 and P2P_2, and each of the processes spawns two threads T1T_1 and T2T_2:

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?

Sign in to save attempts.

Solutions and discussion are hidden while you attempt this question. They open once you check or show the answer.