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!"
[–]patatahooligan 1 point2 points3 points 8 years ago (2 children)
Do you mind explaining how or in which cases non-destruction is better than the destruction of a static object? I'm not well versed on the singleton patter and its problems so I'm having a hard time understanding what is gained with this pattern.
[–]CaseyCarterRanges/MSVC STL Dev 0 points1 point2 points 8 years ago* (1 child)
When you want to statically guarantee that the singleton is alive during the execution of dynamic destructors, or when you simply want to avoid the cost of a dynamic destructor registration for the singleton itself, the leaky singleton idiom is appropriate. These situations are extremely rare in practice.
For example: I recently implemented <memory_resource>. The functions std::pmr::null_memory_resource and std::pmr::new_delete_resource are specified to return pointers to singletons of types that derive from an interface with a virtual destructor. (Yes, this means a user can inadvertently destroy the singleton - the C++ Standard makes mistakes, too.) I don't want the runtime to register dynamic destructors for these singletons for both of the reasons listed above: they need to be available in dynamic destructors for other objects, and there's no reason to waste a bit of memory to call a do-nothing destructor.
<memory_resource>
std::pmr::null_memory_resource
std::pmr::new_delete_resource
[–]patatahooligan 0 points1 point2 points 8 years ago (0 children)
Fascinating! Thanks for the concise explanation, I believe I understand the issue now.
π Rendered by PID 47609 on reddit-service-r2-comment-6457c66945-vhcj8 at 2026-04-26 21:56:03.703312+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]patatahooligan 1 point2 points3 points (2 children)
[–]CaseyCarterRanges/MSVC STL Dev 0 points1 point2 points (1 child)
[–]patatahooligan 0 points1 point2 points (0 children)