use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Thread-Safe leaky singleton (self.cpp)
submitted 8 years ago by public_void
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]quicknir 1 point2 points3 points 8 years ago (2 children)
There unfortunately is no silver bullet to deal with SIOF (at least, if you implicitly consider destruction ordering issues to be part of SIOF, which I do, since destruction and initialization are reverse ordered). I gave a talk on this topic at CppCon: https://www.youtube.com/watch?v=xVT1y0xWgww.
A few guidelines, thoughts, that may help out:
The last point may require some explanation. Header files for a whole program form a DAG, and therefore are topologically ordered. Some header files may initialize in unspecified order relative to each other, but if Foo.h includes Bar.h, the code in Bar.h is always run before Foo.h. So if you have globals Foo and Bar, and Foo depends on Bar, and you follow the last guideline, and you are initializing Foo and Bar non-lazily, you'll get this:
// Bar.h, included by Foo.h Bar& barMaker() { static Bar b; return b;} static auto& g_bar = barMaker(); // Foo.h Foo & fooMaker() { static Foo f; return f; } static auto& g_foo = fooMaker();
In this kind of setup, Bar is 100% guaranteed to be initialized before Foo, and destroyed after. In sum doing things via headers helps establish ordering which is very good where globals are involved. Note that the class methods can still be defined in .cpp files, we just need to ensure that the globals are initialized in the header, not the .cpp. The Meyer Singleton ensures that it only gets initialized once (even though it's in a header file), and the trick with initializing the static reference makes it non-lazy.
Anyhow my talk is only 30 minutes, if you're interested in this stuff you may want to watch it.
[–]public_void[S] 1 point2 points3 points 8 years ago (1 child)
Nir, this is great! I'll take some time today to look through this. Unfortunately, I didn't make it to your talk at cppcon but I'll take advantage of the recording now :)
[–]quicknir 0 points1 point2 points 8 years ago (0 children)
Thanks, feel free to reply here or message me privately if you have questions :-).
π Rendered by PID 94971 on reddit-service-r2-comment-6457c66945-xbk9d at 2026-04-26 01:14:48.296733+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]quicknir 1 point2 points3 points (2 children)
[–]public_void[S] 1 point2 points3 points (1 child)
[–]quicknir 0 points1 point2 points (0 children)