Is the snippet below “safe” to perform some initialization once in a multi-threaded program?
I am a little worried that boxing / unpacking may cause some problems ...
private static object initialized = false;
public static void Initialize()
{
lock (initialized)
{
if ((bool)initialized == false)
{
DoInitialization();
initialized = true;
}
}
}
Note that I cannot just initialize from Main or some other single-threaded context.
source
share