Computer Sciences > Gate 2024 Set-2 > Thread
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.
Which of the following outcomes is/are possible when threads T1 and T2 execute concurrently?
A
T1 runs first and prints 1, T2 runs next and prints 2
B
T2 runs first and prints 1, T1 runs next and prints 2
C
T1 runs first and prints 1, T2 does not print anything (deadlock)
D
T2 runs first and prints 1, T1 does not print anything (deadlock)

Explanation

Correct : a

Similar Questions

What is the worst-case time complexity of insertion in an AVL tree?
Question #23 Medium
Which operations on a binary search tree have O(h) complexity?
Question #31 Easy
Compare search complexities of sorted array vs balanced BST.
Question #47 Hard

Related Topics

Data Structures Binary Search Tree Time Complexity Algorithm Analysis Tree Algorithms Computer Science