Does static ctor/dtor behave differently in 2.067-b2?
amber via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Feb 27 15:50:49 PST 2015
Hi All,
I am just wondering if dmd 2067-b2 invokes static this() and
static ~this() differently to 2066.1
I have a strange bug when I use DMD2.067-b2 and it looks a lot
like the static ctor/dtor are run from a separate thread to
main() and unittest{} blocks. When I run under 2066.1 the code
works correcly and behaves as if everything runs in the same
thread (which is what I am expecting).
It's difficult to be sure because "thisTid" under 2067 returns an
actual ID but under 2066.1 it always returns
"Tid(std.concurrency.MessageBox)"
The code below doesn't have the bug but it's what I'm using to
try and figure out the difference between 2066.1 and 2067.
---
import std.concurrency;
import std.stdio;
struct S
{
static int val = 1;
static this(){
writefln("Ctor:%s", thisTid);
val = 2;
}
static ~this() {
writefln("Dtor:%s", thisTid);
val = 0;
}
}
unittest {
S s;
writefln("UT -- s:%s tid:%s", S.val, thisTid);
}
void main() {
S s;
writefln("MAIN -- s:%s tid:%s", S.val, thisTid);
}
---
Thanks,
amber
More information about the Digitalmars-d-learn
mailing list