Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: it seems to me that the bounds checking test for overflow was deficient so i added a second code example i have more confidence in.

...

Wiki Markup
The {{compareAndSet()}} method takes two arguments, the expected value of a variable when the method is invoked and the updated value. This compliant solution uses this method to atomically set the value of {{itemsInInventory}} to the updated value if and only if the current value equals the expected value \[[API 06|AA. Java References#API 06]\]. The while loop ensures that the {{removeItem()}} method succeeds in decrementing the most recent value of {{itemsInInventory}} as long as the inventory count is greater than {{MIN_INVENTORY}}. Refer to [CON02VNA02-J. Ensure that compound operations on shared variables are atomic] for more details.

...