The abridged problem (Y)
Suppose you need to know, from within a function, whether this function has been called as part of the initialization of a static object, or not. Is there a standard or platform-specific way to do so?
The backstory (X)
I'm knee-deep into the source code of a DLL that is used by many applications. This DLL exposes an Init
function, and this function should construct a boost::asio::deadline_timer
to be used later (but the DLL can work without it in a degraded mode).
The issue is that the timer cannot be constructed during the initialization of static objects (DLL load time), lest its constructor deadlock.
Of course, everyone and their cat calls Init
from everywhere (yes, multiple times!), including static constructors from source code I shan't edit, hence the need to detect that situation and bail out.
After pragmatism overcame disgust, I ended up walking up the callstack to try and find wWinMain
and deduce that static initialization is over. It's awful and doesn't work with dynamically-loaded binaries, which thankfully was outside the scope of my particular case. I sure wish there were a cleaner way.