Possible outcomes of indivisible updates

An engineering program uses two threads to update a shared, dimensionless integer x, initially equal to 3. Each labelled operation is an atomic update: its read, calculation and write act as one indivisible step.


Thread A performs A1, x = x + 4, followed by A2, x = 2 * x. Thread B performs B1, x = x - 1, followed by B2, x = 3 * x.


Assume every execution places these four operations in one total order that preserves the order within each thread. Every such order is possible. All four operations finish exactly once, arithmetic is exact, and no other code accesses x. The main thread reads x only after both worker threads finish.


Two separate operation chains show the required order of updates within Thread A and Thread B.


Determine the minimum possible final value of x, the maximum possible final value of x, and the number of distinct possible final values. Report all three answers as exact integers.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Threads and Concurrency Questions: