Thursday, September 23, 2010

Double-check Locking Pattern

The 'Double-check Locking Pattern' is used for getting instances of a singleton without always having to go through a guard.

First you check the pointer to the singleton object, then enter the guard's scope, then check the pointer again. Once the pointer is set, you no longer use the guard.

Reference: Modern C++ Design: Generic Programming and Design Patterns Applied by Andrei Alexandrescu. Addison-Wesley, 2001, pp. 146-147.

No comments:

Post a Comment