GATE CS 2024 Set 2 | Question 46

Operating Systems › Process Synchronization · MSQ · 2 marks · Answer: B, C

  1. Question 46Operating Systemsmsq2 marks
    T1: wait(s1); x=x+1; print(x); wait(s2); signal(s1). T2: wait(s1); x=x+1; print(x); signal(s2); signal(s1). s1=1, s2=0, x=0. Which outcomes are possible?
    • A.
      T1 first prints 1, T2 next prints 2
    • B.
      T2 first prints 1, T1 next prints 2
      ✓
    • C.
      T1 first prints 1, T2 deadlock
      ✓
    • D.
      T2 first prints 1, T1 next prints 2 (no deadlock)

    Answer: B, C

    Solution

    Answer: (B) and (C) - If T2 acquires s1 first: it prints 1, signals s2, signals s1; then T1 acquires s1, prints 2, wait(s2) succeeds (s2=1), signal(s1). Works -> (B) possible. - If T1 acquires s1 first: it prints 1, then wait(s2) blocks (s2=0) while still holding s1; T2 can never get s1 -> deadlock -> (C) possible. - (A) impossible (T1 first always deadlocks). (D) impossible (T2 first prints 1 then T1 prints 2 is exactly (B), not a new distinct option as worded — the valid non-deadlock case is (B)).

More GATE PYQ on Process Synchronization

All GATE CS Operating Systems PYQ →

Attempt GATE CS 2024 Set 2 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →