The document is about a design pattern called double locking, which is 
especially suitable for singleton objects in multithreaded environments.

The pattern is essentially this:

static Singleton *instance (void)
{
// First check
if (instance_ == 0)
{
// Ensure serialization (guard
// constructor acquires lock_).
Guard<Mutex> guard (lock_);
// Double check.
if (instance_ == 0)
instance_ = new Singleton;
}
return instance_;
// guard destructor releases lock_.
}

The guard mutex is only accessed in the initialization phase of the singleton. 
Once instance_ is set the guard does not need to be queried anymore.

Richard
_______________________________________
Von: [email protected] 
[mailto:[email protected]] Im Auftrag von Robert 
Osfield
Gesendet: Dienstag, 17. März 2009 11:07
An: OpenSceneGraph Users
Betreff: Re: [osg-users] Multithreading crash duetoosgDb::Registry::instance()

2009/3/17 Schmidt, Richard <[email protected]>
http://www.cs.wustl.edu/~schmidt/PDF/DC-Locking.pdf

Could you explain what the above document is all about...

Robert.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to