
Pedro Lamarão
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