Double-Checked Locking An Optimization Pattern for Efficiently Initializing and Accessing Thread-safe Objects

Douglas C. Schmidt, Tim G. Harrison · 1998

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. 1Intent The Double-Checked Locking optimization pattern reduces contention and synchronization overhead whenever "critical sections" of code need to acquire locks just once, but must be thread-safe when they do acquire locks. 2 Also Known As Lock Hint [2] 3 Motivation 3.1 The Canonical Singleton Developing correct and efficient concurrent applications is ...

Read the paper · More papers on PaperTik