Main Page Namespace List Class Hierarchy Compound List Compound Members

# ZThread::Singleton Class Template Reference

`#include <Singleton.h>`

List of all members.

## Static Public Methods
LONESOME* | instance ()
## Static Protected Attributes
LOCK | _lock
bool | _flag
LONESOME* | _Instance
SingletonDestroyer<LONESOME> | _Destroyer

## Detailed Description

### template<class LONESOME, class LOCK = ZThread::Mutex> class ZThread::Singleton

Author:
  Eric Crahen

Date:
  06-07-2001

Version:
  1.4.3

Based on the work of John Vlissidles in his book 'Pattern Hatching' and on an article by Douglas Schmidtt on double checked locking.

This is a thread safe wrapper for creating Singleton classes. The Singleton class is of type LONESOME and is automatically constructed the first time it is used, it will then persist for the lifetime of the program.

## Member Function Documentation

LONESOME * instance ( | )`[inline, static]`

| Provide access to the single instance through double-checked locking Returns: LONESOME* single instance

## Member Data Documentation

SingletonDestroyer< LONESOME > _Destroyer`[static, protected]`

| SingletonDestroyer that is created to destroy this Singleton

LONESOME * _Instance`[static, protected]`

| LONESOME* for the actual object this Singleton is providing access to.

bool _flag`[static, protected]`

| Flag to keep over-aggressive compilers from optimizing away the double check

LOCK _lock`[static, protected]`

| Mutex used to perform to double-checked locking that makes this Singleton thread safe

The documentation for this class was generated from the following file:

- Singleton.h