in Operating System retagged by
531 views
4 votes
4 votes

Consider three concurrently executing threads in the same process using two semaphores $\text{s}1$ and $\text{s2}.$ Assume $\text{s1}$ has been initialized to $1$, while $\text{s2}$ has been initialized to $0.$ What are the possible values of the global variable $x,$ initialized to $0,$ after all three threads have terminated?

/* thread A */
P(s2); 
P(s1);
x = x*2; 
V(s1);
/* thread B */
P(s1); 
x = x*x; 
V(s1);
/* thread C */ 
P(s1); 
x = x+3; 
V(s2); 
V(s1);
  1. $6$
  2. $12$
  3. $18$
  4. $36$
in Operating System retagged by
531 views

1 comment

edited by

$ \large{\colorbox{yellow}{Detailed video solution of this question with direct time stamp}} $

All India Mock Test 2 - Solutions Part 1

0
0

2 Answers

3 votes
3 votes
The possible sequences are $B,C,A (x = 6)$ or $C,A,B (x = 36)$ or $C,B,A (x = 18).$
edited by
0 votes
0 votes

All possible values of the variable are:6,18,36.


The value 6 is possible by order:
T(B)->T(C)->T(A).


The value 18 is possible by order:

T(C)->T(B)->T(A).

The value 36 is possible by order:

T(C)->T(A)->T(B).

Since only thread B or thread C can occur initially due to P(s1), as s2 is initialized to 0

ANS:(A),(C),(D)

Answer:

Related questions