2 ms·
But the argument to println is evaluated before println is called! Whatever synchronization it's doing internally therefore can't affect what it prints. Seems
by ScottBurson 13y ago
But the argument to println is evaluated before println is called! Whatever synchronization it's doing internally therefore can't affect what it prints.
Seems to me, either there's something synchronized in Integer.toString (which seems undesirable and therefore unlikely) or, statistically, in the rare cases that the writes don't take effect in time for the 'if' predicate, they do take effect a few nanoseconds later, in time for the conversions involved in the string construction. (Actually p.x is the only one at risk here, statistically speaking; the conversion of its value to a string will take plenty long enough for the write of p.y to take effect. Combine that with the fact that the write of p.x probably still precedes that of p.y, so that the one that's wrong in the 'if' statement is probably p.y, and you see that the odds of the wrong values being printed are vanishingly small.)