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

Static Public Member Functions | |
| static singleClass * | instance () |
| |
Protected Member Functions | |
| Singleton () | |
| Don't create a singleton with new! use instance(). | |
| virtual | ~Singleton () |
| don't delete a singleton! | |
class myClass : public vpr::Singleton<myClass>
| singleClass | The type to be used a singleton. |
Definition at line 117 of file Singleton.h.
| vpr::Singleton< singleClass >::Singleton | ( | ) | [inline, protected] |
| virtual vpr::Singleton< singleClass >::~Singleton | ( | ) | [inline, protected, virtual] |
| static singleClass* vpr::Singleton< singleClass >::instance | ( | ) | [inline, static] |
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 127 of file Singleton.h.
Referenced by vpr::InetAddrSIM::setAddress().
00128 { 00129 // WARNING! race condition possibility, creation of static vars 00130 // are not thread safe. This is only an issue when creating 00131 // your first thread, since it uses a singleton thread manager, 00132 // the two threads might both try to call instance at the same time 00133 // which then the creation of the following mutex would not be certain. 00134 static vpr::Mutex singleton_lock1; 00135 static singleClass* the_instance1 = NULL; 00136 00137 if (the_instance1 == NULL) 00138 { 00139 vpr::Guard<vpr::Mutex> guard(singleton_lock1); 00140 if (the_instance1 == NULL) 00141 { 00142 the_instance1 = new singleClass; 00143 } 00144 } 00145 return the_instance1; 00146 }
1.5.1