[osg-users] Multithreading crash duetoosgDb::Registry::instance()

Schmidt, Richard Richard.Schmidt at eads.com
Tue Mar 17 03:17:26 PDT 2009


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: osg-users-bounces at lists.openscenegraph.org [mailto:osg-users-bounces at lists.openscenegraph.org] 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 <Richard.Schmidt at eads.com>
http://www.cs.wustl.edu/~schmidt/PDF/DC-Locking.pdf

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

Robert.



More information about the osg-users mailing list