Skip to content

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

GateBrew
← GATE CSE 2024 Set 2
Questions

Q36

MSQ2 marksOperating systems

Consider a multi-threaded program with two threads T1\mathrm{T} 1 and T2\mathrm{T} 2. The threads share two semaphores: s1s1 (initialized to 11) and s2s2 (initialized to 00). The threads also share a global variable x\mathrm{x} (initialized to 00). The threads execute the code shown below.

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

Which of the following outcomes is/are possible when threads T1\mathrm{T} 1 and T2\mathrm{T} 2 execute concurrently?

Sign in to save attempts.

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