/* Collection of code snippets by Arne Vajhøj */
/* (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) */
#ifndef Volatile_SINGLETON_H
#define Volatile_SINGLETON_H

#include <iostream>

using namespace std;


// **** double lock with volatile singleton pattern is not thread safe - never use it ****
class VolatileSingleton
{
private:
    static volatile VolatileSingleton* volatile instance;
    int SomeState;
    VolatileSingleton() { SomeState = 123; }
    VolatileSingleton(const VolatileSingleton& original) { };
    VolatileSingleton& operator=(const VolatileSingleton& original) { return *this; };
public:
    static volatile VolatileSingleton* volatile Instance();
    void SomeMethod() { cout << SomeState << endl; }
};

#endif
