News for hackers. Stuff that matters.
Re:Best Performance of a C++ Singleton by csegaults on Sunday March 08, 2026 @01:09AM (#47294970)
Err how does the static approach suffer from thread safety issues when the initialization happens before main even runs?

I might be responding to a llm so...

Re:Best Performance of a C++ Singleton by halayli on Sunday March 08, 2026 @01:28AM (#47295076)
a real human. threads can exist before main() starts. for example, you can include another tu which happens to launch a thread and call instance(). Singletons used to be a headache before C++11 and it was common(maybe still is) to see macros in projects that expand to a singleton class definition to avoid common pitfalls.
Re:Best Performance of a C++ Singleton by MaulingMonkey on Sunday March 08, 2026 @04:46AM (#47295689)
In fact, Windows 10+ now uses a thread pool during process init well before main is reached.

https://web.archive.org/web/20200920132133/https://blogs.bla...

Re:Best Performance of a C++ Singleton by platinumrad on Sunday March 08, 2026 @01:14AM (#47294993)
It's a bit contrived, but a global with a nontrivial constructor can spawn a thread that uses another global, and without synchronization the thread can see an uninitialized or partially initialized value.
Re:Best Performance of a C++ Singleton by jibal on Sunday March 08, 2026 @03:47AM (#47295425)
@dang There should be an HN guideline against such accusations.