Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Double-checked locking
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Software design pattern}} In [[software engineering]], '''double-checked locking''' (also known as "double-checked locking optimization"<ref>Schmidt, D et al. Pattern-Oriented Software Architecture Vol 2, 2000 pp353-363</ref>) is a [[software design pattern]] used to reduce the overhead of acquiring a [[Lock (computer science)|lock]] by testing the locking criterion (the "lock hint") before acquiring the lock. Locking occurs only if the locking criterion check indicates that locking is required. The original form of the pattern, appearing in ''Pattern Languages of Program Design 3'',<ref>{{cite book |title=Pattern languages of program design. 3 |date=1998 |publisher=Addison-Wesley |location=Reading, Mass |isbn=978-0201310115 |edition=Nachdr. |url=https://www.dre.vanderbilt.edu/~schmidt/PDF/DC-Locking.pdf}}</ref> has [[data race]]s, depending on the [[Memory model (programming)|memory model]] in use, and it is hard to get right. Some consider it to be an [[anti-pattern]].<ref>{{cite book |last1=Gregoire |first1=Marc |title=Professional C++ |date=24 February 2021 |publisher=John Wiley & Sons |isbn=978-1-119-69545-5 |url=https://books.google.com/books?id=MyEgEAAAQBAJ&pg=PA946 |language=en}}</ref> There are valid forms of the pattern, including the use of the {{java|volatile}} keyword in Java and explicit memory barriers in C++.<ref name="bdec">David Bacon et al. [http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html The "Double-Checked Locking is Broken" Declaration].</ref> The pattern is typically used to reduce locking overhead when implementing "[[lazy initialization]]" in a multi-threaded environment, especially as part of the [[Singleton pattern]]. Lazy initialization avoids initializing a value until the first time it is accessed.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)