Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The getSum() method contains a data race. For example, if a and b currently have the values 0 and Integer.MAX_VALUE, respectively, and one thread calls getSum() while another calls setValues(Integer.MAX_VALUE, 0), getSum() might return 0 , or Integer.MAX_VALUE, or it might overflow and wrap. Overflow will occur when the first thread reads a and b, after the second thread has set the value of a to Integer.MAX_VALUE but before it has set the value of b to 0.

...