> Here's an optimization for Math.random() that appears to be safe, > despite the double-check access: >
It is just barely safe because of Random internals that preclude reordering of the field ref assignment. It would be nicer (and no slower) to put a Fences.orderWrites() here. Assuming we add Fences API for Java7. http://gee.cs.oswego.edu/dl/jsr166/dist/docs/java/util/concurrent/atomic/Fences.html In the mean time, it would be good to include a more careful explanation in the comments so people don't blindly copy/paste/hack this construction when it doesn't apply. Greetings from Toronto (ISMM/PLDI) -Doug > http://cr.openjdk.java.net/~martin/webrevs/openjdk7/Math.random/ > > David, if you agree, could you file a bug? > > Thanks, > > Martin >