DOUBLE-CHECKED LOCKING An Object Behavioral Pattern for Initializing and Accessing Thread-safe Objects Efficiently Douglas C. Schmidt and Timothy H. Harrison schmidt@cs.wustl.edu and harrison@cs.wustl.edu Department of Computer Science Washington University Campus Box 1045 One Brookings Drive St. Louis, Missouri 63130-4899 (TEL): (314) 935-7538 ABSTRACT Developing correct and efficient concurrent applications is hard. Programmers must learn new mechanisms (such as multi-threading and synchronization APIs) and techniques (such as concurrency control and deadlock avoidance algorithms). In addition, many familiar design patterns (such as Singleton or Observer) that work well for sequential programs contain subtle assumptions that do not apply in the context of concurrency. This paper examines how the canonical implementation of the Singleton pattern does not work correctly in the presence of preemptive multi-tasking or true parallelism. To solve this problem, we describe another pattern, Double-Checked Locking, which ensures that objects are initialized atomically and unnecessary locking overhead is eliminated on each access to the object's state. This example illustrates how changes in underlying forces ({\em i.e.,} the addition of multi-threading and parallelism to Singleton) can impact the form and content of patterns used to develop concurrent software.