[Issue 22681] rt_moduleTlsCtor/Dtor() don't work with phobos dynamically linked
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jan 16 21:53:15 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22681
--- Comment #1 from duser at airmail.cc ---
slightly longer example with a C main showing `rt_init()`:
```
__gshared int ctors, dtors;
static this() { ctors++; }
static ~this() { dtors++; }
import core.runtime;
import core.thread;
import core.stdc.stdio;
extern(C) int main() {
rt_init();
printf("ctors %d dtors %d (should be 1 0) - main\n", ctors, dtors);
ctors = 0;
dtors = 0;
createLowLevelThread({
scope(failure) assert(0); // satisfy nothrow
thread_attachThis();
rt_moduleTlsCtor();
printf("ctors %d dtors %d (should be 1 0) - ll thread\n",
ctors, dtors);
rt_moduleTlsDtor();
thread_detachThis();
}).joinLowLevelThread;
printf("ctors %d dtors %d (should be 1 1) - ll thread\n", ctors,
dtors);
ctors = 0;
dtors = 0;
auto t = new Thread({
printf("ctors %d dtors %d (should be 1 0) - D thread\n", ctors,
dtors);
});
t.start();
t.join();
printf("ctors %d dtors %d (should be 1 1) - D thread\n", ctors, dtors);
ctors = 0;
dtors = 0;
rt_term();
printf("ctors %d dtors %d (should be 0 1) - main\n", ctors, dtors);
return 0;
}
```
the only difference with dynamic phobos is that the constructors for the
low-level thread don't run (OS threads with pthread are also affected)
`rt_init()` successfully inits them for the main thread, and so does `new
Thread()` for the D thread
--
More information about the Digitalmars-d-bugs
mailing list