Why are multiple singleton class objects in hungry man mode started in an uncertain order? Why can the startup order of multiple singleton class objects in lazy mode be controlled?
Asked
Active
Viewed 42 times
0
-
What's "hungry man mode" and "lazy mode"? I'm for one am not familiar with these terms. It would be best if you show a [mcve] that illustrates whatever problem you are having. – Igor Tandetnik Feb 21 '22 at 05:12
-
Related: https://stackoverflow.com/questions/12755539/why-is-singleton-considered-an-anti-pattern – Marek R Feb 21 '22 at 10:35
1 Answers
0
Initialization of global across multiple translation units is unspecified.
Global at function scope (so static
variable) are initialized only when function is called the "first" time. You might have control on when you call functions (you can still call them in unspecified order, but you should normally be able to call them in the order you want).

Jarod42
- 203,559
- 14
- 181
- 302