#include <Singleton.h>
Inheritance diagram for vpr::Singleton:

Static Public Methods | |
| singleClass * | instance (void) |
| NOTE: currently, func is thread safe after first call to instance(). More... | |
Protected Methods | |
| Singleton () | |
| Don't create a singleton with new! use instance(). More... | |
| virtual | ~Singleton () |
| don't delete a singleton! More... | |
class myClass : public vpr::Singleton<myClass>
Definition at line 107 of file Singleton.h.
|
|||||||||
|
Don't create a singleton with new! use instance().
Definition at line 141 of file Singleton.h.
00142 {
00143 }
|
|
|||||||||
|
don't delete a singleton!
Definition at line 146 of file Singleton.h.
00147 {
00148 }
|
|
||||||||||
|
NOTE: currently, func is thread safe after first call to instance(). if first call to instance happens multiple times simultaneously then don't be surprised when something dies because of a mutex.. this bug can be caused by spawning two threads immediately after entering main() Definition at line 117 of file Singleton.h.
00118 {
00119 // WARNING! race condition possibility, creation of static vars
00120 // are not thread safe. This is only an issue when creating
00121 // your first thread, since it uses a singleton thread manager,
00122 // the two threads might both try to call instance at the same time
00123 // which then the creation of the following mutex would not be certain.
00124 static vpr::Mutex singleton_lock1;
00125 static singleClass* the_instance1 = NULL;
00126
00127 if (the_instance1 == NULL)
00128 {
00129 vpr::Guard<vpr::Mutex> guard( singleton_lock1 );
00130 if (the_instance1 == NULL)
00131 { the_instance1 = new singleClass; }
00132 }
00133 return the_instance1;
00134 }
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002