Skip to content

Commit

Permalink
Run thread-local static ctors and dtors on macOS
Browse files Browse the repository at this point in the history
From the documentation on thread_attachThis
(https://dlang.org/phobos/core_thread.html#.thread_attachThis):

> NOTE:
> This routine does not run thread-local static constructors when
> called. If full functionality as a D thread is desired, the
> following function must be called after thread_attachThis:
>
> extern (C) void rt_moduleTlsCtor();

thread_detachThis
(https://dlang.org/phobos/core_thread.html#.thread_detachThis)
has a similar note about calling rt_moduleTlsDtor after
thread_detachThis.

This prevents bugs like the following:
SimonN/LixD#121
  • Loading branch information
emlai committed Jul 19, 2016
1 parent f59b201 commit cd06e65
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions allegro5/system.d
Expand Up @@ -24,14 +24,20 @@ else
}
}

extern (C) void rt_moduleTlsCtor();
extern (C) void rt_moduleTlsDtor();

int al_run_allegro(scope int delegate() user_main)
{
extern(C) static int main_runner(int argc, char** argv)
{
version(OSX)
{
version(D_Version2)
{
thread_attachThis();
rt_moduleTlsCtor();
}
else
Thread.thread_attach();
}
Expand All @@ -41,7 +47,10 @@ int al_run_allegro(scope int delegate() user_main)
version(OSX)
{
version(D_Version2)
{
thread_detachThis();
rt_moduleTlsDtor();
}
else
Thread.thread_detach();
}
Expand Down

0 comments on commit cd06e65

Please sign in to comment.