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

Robert Osfield robert.osfield at gmail.com
Tue Mar 17 03:21:38 PDT 2009


HI Richard + Paul,

Thanks for explanation.  Feel free to dive in an code up such a solution.

Robert.

On Tue, Mar 17, 2009 at 10:17 AM, Schmidt, Richard <Richard.Schmidt at eads.com
> wrote:

> 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<http://www.cs.wustl.edu/%7Eschmidt/PDF/DC-Locking.pdf>
>
> Could you explain what the above document is all about...
>
> Robert.
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20090317/4f6bff17/attachment-0003.htm>


More information about the osg-users mailing list