[D-runtime] Trouble with thread attaching/detaching on Linux
Sean Kelly
sean at invisibleduck.org
Fri Jan 20 11:15:43 PST 2012
This looks roughly correct. I hadn't thought about adding calls to TlsCtor and TlsDtor, though perhaps I should. Comments inline.
On Jan 20, 2012, at 6:20 AM, Alex wrote:
> Hi,
>
> (Sorry if this is posted in the wrong place.)
>
> Consider the following code:
>
> import core.sys.posix.pthread,
> core.memory,
> core.thread,
> std.stdio;
>
> extern (C) void rt_moduleTlsCtor();
> extern (C) void rt_moduleTlsDtor();
>
> __gshared pthread_key_t key;
>
> static this() { writefln("TLS ctor"); }
> static ~this() { writefln("TLS dtor"); }
>
> static extern(C) void* threadMain(void *arg)
> {
> pthread_setspecific(key, cast(void*)0xbadc0de);
>
> thread_attachThis();
> rt_moduleTlsCtor();
>
> writefln("Hello from thread");
>
> return null;
> }
>
> private static extern (C) void threadExit(void *cd)
> {
> writefln("Bye from thread");
>
> GC.disable();
> thread_detachThis();
> rt_moduleTlsDtor();
You might want to reverse the detach and TlsDtor calls here, since it's possible that static dtors might want access to the current Thread object.
More information about the D-runtime
mailing list