Double-Checked Locking An Optimization Pattern for Efficiently Initializing and Accessing Thread-safe Objects
نویسندگان
چکیده
This paper shows how the canonical implementation [1] of the Singleton pattern does not work correctly in the presence of preemptive multi-tasking or true parallelism. To solve this problem, we present the Double-Checked Locking optimization pattern. This pattern is useful for reducing contention and synchronization overhead whenever “critical sections” of code should be executed just once. In addition, Double-Checked Locking illustrates how changes in underlying forces (i.e., adding multi-threading and parallelism to the common Singleton use-case) can impact the form and content of patterns used to develop concurrent software.
منابع مشابه
Double-Checked Locking An Object Behavioral Pattern for Initializing and Accessing Thread-safe Objects Efficiently
This paper shows how the canonical implementation [1] of the Singleton pattern does not work correctly in the presence of preemptive multi-tasking or true parallelism. To solve this problem, we present the Double-Checked Locking pattern. This pattern is useful for reducing contention and synchronization overhead whenever “critical sections” of code rarely need to acquire locks. In addition, the...
متن کاملC + + and the Perils of Double - Checked Locking ∗
Google the newsgroups or the web for the names of various design patterns, and you’re sure to find that one of the most commonly mentioned is Singleton. Try to put Singleton into practice, however, and you’re all but certain to bump into a significant limitation: as traditionally implemented (and as we explain below), Singleton isn’t thread-safe. Much effort has been put into addressing this sh...
متن کاملUsing Design Patterns and Frameworks to Develop Object-Oriented Communication Systems
Factory 19 Tactical Patterns Proxy { \Provide a surrogate or placeholder for another object to control access to it" Strategy { \De ne a family of algorithms, encapsulate each one, and make them interchangeable" Adapter { \Convert the interface of a class into another interface client expects" Singleton { \Ensure a class only has one instance and provide a global point of access to it" State { ...
متن کاملStrategized Locking, Thread-safe Interface, and Scoped Locking Patterns and Idioms for Simplifying Multi-threaded C++ Components
Developing multi-threaded applications is hard since incorrect use of locks can cause subtle and pernicious errors. Likewise, developing multi-threaded reusable components is hard since it can be time-consuming to customize components to support new, more efficient locking strategies. This paper describes a pair of patterns, Strategized Locking and Thread-safe Interface, and a C++ idiom, Scoped...
متن کاملThread-Specific Storage for C/C++ An Object Behavioral Pattern for Accessing per-Thread State Efficiently
In theory, multi-threading an application can improve performance (by executing multiple instruction streams simultaneously) and simplify program structure (by allowing each thread to execute synchronously rather than reactively or asynchronously). In practice, multi-threaded applications often perform no better, or even worse, than single-threaded applications due to the overhead of acquiring ...
متن کامل