Re: JDK 8 RFC 6470700: Math.random() / Math.initRNG() uses "double checked locking"

2013-08-26 Thread Aleksey Shipilev
On 08/22/2013 03:37 AM, Brian Burkhalter wrote: > With respect to this issue > > http://bugs.sun.com/view_bug.do?bug_id=6470700 > > the code of concern from java.lang.Math is > > 701private static Random randomNumberGenerator; > 702 > 703private static synchronized Random initRNG() { > 7

Re: JDK 8 RFC 6470700: Math.random() / Math.initRNG() uses "double checked locking"

2013-08-21 Thread Mike Duigou
On Aug 21 2013, at 17:01 , David M. Lloyd wrote: > On 8/21/13 5:37 PM, Brian Burkhalter wrote: >> With respect to this issue >> >> http://bugs.sun.com/view_bug.do?bug_id=6470700 >> >> the code of concern from java.lang.Math is >> >> 701private static Random randomNumberGenerator; >> 702 >>

Re: JDK 8 RFC 6470700: Math.random() / Math.initRNG() uses "double checked locking"

2013-08-21 Thread Vitaly Davidovich
There's a significant difference here: Random reads the field into a local and then operates only on the local. Looking at the code, I only see one possible (bizarre) circumstance where you can hit NPE. If code was transformed to: static double random() { Random rnd = randomNumberGenerator

Re: JDK 8 RFC 6470700: Math.random() / Math.initRNG() uses "double checked locking"

2013-08-21 Thread Steven Schlansker
On Aug 21, 2013, at 4:37 PM, Brian Burkhalter wrote: > With respect to this issue > > http://bugs.sun.com/view_bug.do?bug_id=6470700 > > the code of concern from java.lang.Math is > > 701private static Random randomNumberGenerator; > 702 > 703private static synchronized Random initRN

Re: JDK 8 RFC 6470700: Math.random() / Math.initRNG() uses "double checked locking"

2013-08-21 Thread Brian Burkhalter
On Aug 21, 2013, at 5:01 PM, David M. Lloyd wrote: > I don't think you'd want to introduce the overhead of synchronization here. No, I don't. My example code was just that. > It may be better in this case to use this kind of lazy init pattern: > >static final class Holder { >static

Re: JDK 8 RFC 6470700: Math.random() / Math.initRNG() uses "double checked locking"

2013-08-21 Thread David M. Lloyd
On 8/21/13 5:37 PM, Brian Burkhalter wrote: With respect to this issue http://bugs.sun.com/view_bug.do?bug_id=6470700 the code of concern from java.lang.Math is 701private static Random randomNumberGenerator; 702 703private static synchronized Random initRNG() { 704Random rnd =