2 ms·
> so the signed integer you're using to count stuff up from zero might be -16 now, which is astonishing Actually, if it is an int, it is guaranteed to not be a
by kaba0 4y ago
> so the signed integer you're using to count stuff up from zero might be -16 now, which is astonishing
Actually, if it is an int, it is guaranteed to not be any number not explicitly set to (java has no-out-of-thin-air guarantees for 32-bit primitives). In practice on every modern implementation it is true of 64-bit primitives as well.
So the prototypical data race condition of incrementing a primitive counter from n threads can loose counts, but will never have any value outside the 0..TRUE_COUNT range.
- tialaramex 4y agoOoh, I did not know this. Do you happen to know where the "no-out-of-thin-air" guarantee is for the 32-bit primitives? Presumably in the Memory model docs somewhere?
- kaba0 4y agoI quickly glanced at the spec, but didn’t find it. But I didn’t make it up though, I remember reading it on the jvm mailing list and I found it here described by Brian Goetz himself: https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/03-vm-model https://openjdk.org/projects/valhalla/design-notes/state-of-...
- tialaramex 4y agoThanks for that, it makes sense but it's good to know somebody specifically thought about this rather than "Eh, it seems to work".