Remix.run Logo
csegaults 3 hours ago

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...

halayli 3 hours ago | parent | next [-]

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.

MaulingMonkey an hour ago | parent [-]

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...

platinumrad 3 hours ago | parent | prev | next [-]

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.

jibal 2 hours ago | parent | prev [-]

@dang There should be an HN guideline against such accusations.