The program follows to use a shared binary semaphore T. [code]Process A int Y; A1: Y = X*2; A2: X = Y; signal(T);

The program follows to use a shared binary semaphore T.
Code:
Process A  
int Y;            
A1: Y = X*2;      
A2: X = Y;        
signal(T);        
Process B
int Z;
B1: wait(T);
B2: Z = X+1;
X = Z;
T is set to 0 before either process begins execution and, as before, X is set to 5.
Now, how many different values of X are possible after both processes finish executing?
A. one
B. two
C. three
D. four
 
Answer: a
Explanation: The semaphore T ensures that all the statements from A finish execution before B begins. So now there is only one way in which statements from A and B can be interleaved:
A1 A2 B1 B2: X = 11.
 

Tìm kiếm

Back
Top