Answer: A
Let the atomic statements of the two threads be labeled as follows:
- Thread T1:
- A1:a=a+1
- B1:b=b+1
- Thread T2:
- B2:b=2∗b
- A2:a=2∗a
Since the internal statement order within each thread must be preserved, A1 must execute before B1, and B2 must execute before A2. Starting with initial values a=1,b=1, we trace all possible interleavings:
- A1→B1→B2→A2:
- a=1+1=2⟹b=1+1=2⟹b=2×2=4⟹a=2×2=4
- Result: (a=4,b=4)
- A1→B2→B1→A2:
- a=2⟹b=2×1=2⟹b=2+1=3⟹a=2×2=4
- Result: (a=4,b=3)
- A1→B2→A2→B1:
- a=2⟹b=2⟹a=2×2=4⟹b=2+1=3
- Result: (a=4,b=3)
- B2→A2→A1→B1:
- b=2×1=2⟹a=2×1=2⟹a=2+1=3⟹b=2+1=3
- Result: (a=3,b=3)
- B2→A1→A2→B1:
- b=2⟹a=2⟹a=2×2=4⟹b=2+1=3
- Result: (a=4,b=3)
- B2→A1→B1→A2:
- b=2⟹a=2⟹b=2+1=3⟹a=2×2=4
- Result: (a=4,b=3)
Thus, the only possible final combinations of (a,b) are (a=4,b=4), (a=3,b=3), and (a=4,b=3).