GATE Assistant

Past questions › Computer Science and Information Technology › GATE 2024 set2

GATE 2024 set2 · CS · MSQ · 2 marks · Operating System › Process Synchronization

GATE 2024 set2 Computer Science and Information Technology question: Consider a multi-threaded program with two threads T1 and T2 . The threads share two…

Consider a multi-threaded program with two threads T1 and T2. The threads share two semaphores: s1 (initialized to 1) and s2 (initialized to 0). The threads also share a global variable x (initialized to 0). The threads execute the code shown below.

// code of T1          // code of T2
wait(s1);              wait(s1);
x = x+1;               x = x+1;
print(x);              print(x);
wait(s2);              signal(s2);
signal(s1);            signal(s1);

Which of the following outcomes is/are possible when threads T1 and T2 execute concurrently?

  1. (A)

    T1 runs first and prints 1, T2 runs next and prints 2

  2. (B)

    T2 runs first and prints 1, T1 runs next and prints 2

  3. (C)

    T1 runs first and prints 1, T2 does not print anything (deadlock)

  4. (D)

    T2 runs first and prints 1, T1 does not print anything (deadlock)

Show answer

Official answer: B,C

Practise this question with exam-style marking

Discussion

No discussion yet.

Join the discussion