Boost logo

Boost :

Subject: [boost] Thread-safe singleton pattern
From: Andrew Chinkoff (achinkoff_at_[hidden])
Date: 2010-01-25 18:49:46

I propose thread safe singleton pattern implementation

I have attached "singleton.hpp" to this letter.

Below is the test program:

#include <stdio.h>
#include <singleton.hpp>

class A : public boost::Singleton<A>
    // Only Singleton class can create and delete us!
    void foo(){ printf("foo!\n"); }
    A(){ printf("A()\n"); }
    ~A(){ printf("~A()\n"); }

void main()
    // It is not compiled:
    //A a = A::Instance();
    // That is exactly as it should be used:

Test program outputs:

My question: Does Boost community think that boost::Singleton is convenient
(or successful) solution?

Boost list run by bdawes at, gregod at, cpdaniel at, john at