This site is the archived OWASP Foundation Wiki and is no longer accepting Account Requests.
To view the new OWASP Foundation website, please visit https://owasp.org
Difference between revisions of "Code Correctness: Double-Checked Locking"
Line 2: | Line 2: | ||
{{Template:Fortify}} | {{Template:Fortify}} | ||
− | |||
__TOC__ | __TOC__ | ||
− | [[ | + | [[ASDR Table of Contents]] |
+ | |||
+ | Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' | ||
− | |||
==Description== | ==Description== | ||
Line 100: | Line 100: | ||
[[Category:Code Snippet]] | [[Category:Code Snippet]] | ||
[[Category:OWASP ASDR Project]] | [[Category:OWASP ASDR Project]] | ||
+ | [[Category:Vulnerability]] |
Revision as of 11:56, 29 October 2008
This is a Vulnerability. To view all vulnerabilities, please see the Vulnerability Category page.
Last revision (mm/dd/yy): 10/29/2008
Description
Double-checked locking is an incorrect idiom that does not achieve the intended effect.
Many talented individuals have spent a great deal of time pondering ways to make double-checked locking work in order to improve performance. None have succeeded.
Risk Factors
TBD
Examples
At first blush it may seem that the following bit of code achieves thread safety while avoiding unnecessary synchronization.
if (fitz == null) { synchronized (this) { if (fitz == null) { fitz = new Fitzer(); } } } return fitz;
The programmer wants to guarantee that only one Fitzer() object is ever allocated, but does not want to pay the cost of synchronization every time this code is called. This idiom is known as double-checked locking.
Unfortunately, it does not work, and multiple Fitzer() objects can be allocated. See The "Double-Checked Locking is Broken" Declaration for more details [1].
Related Attacks
Related Vulnerabilities
Related Controls
Related Technical Impacts
References
- [[1] D. Bacon et al. The "Double-Checked Locking is Broken" Declaration. http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html.