>
> My suggestions is to stop using static globals altogether - and that does
> _not_ mean you have to use heap allocated objects!
>
> Foo& foo()
> {
>   static Foo foo;
>   return foo;
> }
>
> This will be constructed on first use, is thread safe, and you can
> specifically define the construction order by calling foo somewhere in your
> code.
>
Yeah, I tried that pattern once. I've since learned that the pattern
above is just another instance of the initialization order fiasco.

I had a dependency where one static local had a dependency on another
static local. As fate would have it, I got a bad draw and my Foo
object crashed on destruction because it was using a Bar object that
had already been destroyed.

Al we have managed to do since C++98 (maybe earlier) is move the
problem around because the C++ language has not given us the tools we
need to address the problem.

Jeff

------------------------------------------------------------------------------
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to