Skip to content

Commit

Permalink
fix inf loop in AtomicDouble.max (#874)
Browse files Browse the repository at this point in the history
Before, if there was contention and the body of the loop
was accessed, then it could result in an infinite loop
because it accessed the raw value from the AtomicLong
rather than convert the bits to a double. If the long
bits for `v` treated as a long that is coerced to a double
is smaller than `v`, then the loop condition will never
be satisfied and it loops forever.

Not sure of a good test case to hit this, but the loop
behavior can be reproduced by initializing the max to
the raw long bits and running the `maxNegative` test.
  • Loading branch information
brharrington authored Mar 14, 2021
1 parent ea49b30 commit fb30d1b
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void max(double v) {
if (Double.isFinite(v)) {
double max = get();
while (isGreaterThan(v, max) && !compareAndSet(max, v)) {
max = value.get();
max = get();
}
}
}
Expand Down

0 comments on commit fb30d1b

Please sign in to comment.