Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/core/thread.d
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ version( Solaris )
// this should be true for most architectures
version = StackGrowsDown;

// On Posix (excluding OSX), pthread_key_t is explicitly used to
// store and access thread reference. This is needed
// to avoid TLS access in signal handlers (malloc deadlock)
// when using shared libraries, see issue 11981.
version ( Posix ) version ( Shared ) version = UsePthreadTlsForThreadThis;

/**
* Returns the process ID of the calling process, which is guaranteed to be
* unique on the system. This call is always successful.
Expand Down Expand Up @@ -1151,7 +1157,7 @@ class Thread
{
return sm_this;
}
else version( Posix )
else version( UsePthreadTlsForThreadThis )
{
auto t = cast(Thread) pthread_getspecific( sm_this );
return t;
Expand Down Expand Up @@ -1385,12 +1391,8 @@ private:
{
static Thread sm_this;
}
else version( Posix )
else version( UsePthreadTlsForThreadThis )
{
// On Posix (excluding OSX), pthread_key_t is explicitly used to
// store and access thread reference. This is needed
// to avoid TLS access in signal handlers (malloc deadlock)
// when using shared libraries, see issue 11981.
__gshared pthread_key_t sm_this;
}
else
Expand Down Expand Up @@ -1459,7 +1461,7 @@ private:
{
sm_this = t;
}
else version( Posix )
else version( UsePthreadTlsForThreadThis )
{
pthread_setspecific( sm_this, cast(void*) t );
}
Expand Down Expand Up @@ -1999,8 +2001,11 @@ extern (C) void thread_init()
status = sem_init( &suspendCount, 0, 0 );
assert( status == 0 );

status = pthread_key_create( &Thread.sm_this, null );
assert( status == 0 );
version( UsePthreadTlsForThreadThis )
{
status = pthread_key_create( &Thread.sm_this, null );
assert( status == 0 );
}
}
Thread.sm_main = thread_attachThis();
}
Expand All @@ -2017,7 +2022,7 @@ extern (C) void thread_term()
version( OSX )
{
}
else version( Posix )
else version( UsePthreadTlsForThreadThis )
{
pthread_key_delete( Thread.sm_this );
}
Expand Down