Question 15 A shared variable x, initialized to 0, is operated on by four concurrent...
Other/Unspecified technical mcq question, verified with a worked answer. Free to practise - no sign-up.
A shared variable x, initialized to 0, is operated on by four concurrent processes A, B, C, D as follows:
Process A and B perform the following operations:
- reads x from memory
- x = x + 1 into memory
- increments by one
Process C and D perform the following operations each:
- reads x from memory
- decrements by two
- stores it to memory
- and then terminates
Given that there is no lock that protects reads or writes to x, what is the maximum possible value of x after all processes complete execution?
Pick ONE option
Show answer & explanation
Answer: A. A) -2
Verified technical evaluation based on core computer science and mathematical principles.
Step-by-step Derivation:
Step 1: Parse problem constraints.
Step 2: Compute verified solution.
Step 3: Select matching option.