cogitate / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Suppliers.memoize() should use double-checked locking #532

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Per discussion on guava-discuss.

Original issue reported on code.google.com by kevinb@google.com on 27 Jan 2011 at 7:34

GoogleCodeExporter commented 9 years ago
FYI if you refer to lazy initialization in a multithreaded environment then the 
Double-Checked Locking pattern is broken due to the java memory model 
specification.

Original comment by amer...@gmail.com on 27 Jan 2011 at 8:44

GoogleCodeExporter commented 9 years ago
There's a right and a wrong way to do DCL.  Feel free to review the change if 
you want.

http://code.google.com/p/guava-libraries/source/diff?spec=svn160&r=160&format=si
de&path=/trunk/src/com/google/common/base/Suppliers.java&old_path=/trunk/src/com
/google/common/base/Suppliers.java&old=136

Original comment by kevinb@google.com on 27 Jan 2011 at 8:56

GoogleCodeExporter commented 9 years ago
You're right. Josh Bloch in its effective java 2nd edition clearly demonstrates 
it by using a volative field, as you do ;-) and of course using compilation 
version >= 1.5 to prevent running on java 1.4, as you do too.

Original comment by amer...@gmail.com on 27 Jan 2011 at 10:08

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09