singleton


The os_singleton class is comprised of only one static member function that returns a pointer to a static instance of type T . To access the singleton, use the static method os_singleton< T >::instance() . The scope of the (singleton, type) combination will be the lifetime of the process, and only one instance of the (singleton, type) combination is created.

Use of template gives the flexibility of not having the original classes to inherit from a specific interface class.

The os_singleton class implements the familiar Singleton design pattern using the double-checked locking optimization pattern as described in the paper "Double-Checked Locking, An Optimization Pattern for Efficiently Initializing and Accessing Thread-safe Objects" by Douglas C. Schmidt, and Tim Harrison from the book "Pattern Lagnuages of Program Design 3" published by Addison-Wesley, 1997.

Library

Framework<ToolKit>

Declaration

#include <ospace/framework/singleton.h>

template< class T >
class os_singleton

Interface

instance
/* static */ T* instance()
Returns a pointer to a static instance of type T .

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.