module initialization order issue
Benjamin Thaut
code at benjamin-thaut.de
Sun Mar 3 04:01:11 PST 2013
When modules are initialized, druntime will first run the module
initializers before running the module tls initializers ignoring the
dependencies between the modules. This will lead to a access of a
unitialized module if the module ctor of one module uses tls data of
another module. Example:
module a:
class TLSStuff
{
public int i;
}
TLSStuff g_tlsStuff;
static this()
{
g_tlsStuff = new TLSStuff();
}
module b:
import a;
shared static this()
{
g_tlsStuff.i++; //null pointer access
}
Is this a bug, or is this intended beahvior? I always believed that with
all the dependency detenction that is done such situation should not happen.
Kind Regards
Benjamin Thaut
More information about the Digitalmars-d
mailing list