Boost logo

Boost Users :

From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2007-11-06 05:55:23


Pedro Lamarão <pedro.lamarao_at_[hidden]> writes:

> I've been wondering how boost::mutex plays in the static initialization
> game.

boost::mutex has a default constructor, so is just like any other class in
that regard.

> I'm toying with a "plugin" system where plugins statically register with
> a singleton plugin_manager using a helper struct like this:

> It seems to me there is a static initialization race between every
> register_plugin object and plugin_manager::s_mutex.
>
> Am I just lucky or is there some magic about mutexes in this regard?

You're just lucky. A general solution which does not involve explicitly
checking for initialization every time has not yet been implemented.

To avoid the race, use call_once.

Anthony

-- 
Anthony Williams
Just Software Solutions Ltd - http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net