The following pair of processes share a common variable X. [code] Process A int Y; A1: Y = X*2; A2: X = Y; Process B int Z; B1: Z =

Huyền Thu

New member
The following pair of processes share a common variable X.
Code:
Process A
int Y;
A1: Y = X*2;
A2: X = Y;   
Process B
int Z;
B1: Z = X+1;
B2: X = Z;
X is set to 5 before either process begins execution. As usual, statements within a process are executed sequentially, but statements in process A may execute in any order with respect to statements in process B.
How many different values of X are possible after both processes finish executing?
A. two
B. three
C. four
D. eight
 
Answer: c
Explanation: Here are the possible ways in which statements from A and B can be interleaved.
A1 A2 B1 B2: X = 11
A1 B1 A2 B2: X = 6
A1 B1 B2 A2: X = 10
B1 A1 B2 A2: X = 10
B1 A1 A2 B2: X = 6
B1 B2 A1 A2: X = 12.
 

Tìm kiếm

Back
Top