Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Issue 5488 - Spawned threads hang in a way that suggests allocation o…
Browse files Browse the repository at this point in the history
…r gc issue
  • Loading branch information
complexmath committed Feb 2, 2011
1 parent ae1c263 commit 1449d7b
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/core/sync/condition.d
Expand Up @@ -570,8 +570,8 @@ version( unittest )
synchronized( mutex )
{
waiting = true;
alertedOne = condReady.wait( 10_000_000 ); // 1s
alertedTwo = condReady.wait( 10_000_000 ); // 1s
alertedOne = condReady.wait( dur!"seconds"(1) );
alertedTwo = condReady.wait( dur!"seconds"(1) );
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/core/sync/exception.d
Expand Up @@ -20,8 +20,13 @@ module core.sync.exception;
*/
class SyncException : Exception
{
this( string msg )
this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null)
{
super( msg );
super(msg, file, line, next);
}

this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__)
{
super(msg, file, line, next);
}
}
34 changes: 10 additions & 24 deletions src/core/sync/mutex.d
Expand Up @@ -62,8 +62,16 @@ class Mutex :
}
else version( Posix )
{
int rc = pthread_mutex_init( &m_hndl, &sm_attr );
if( rc )
pthread_mutexattr_t attr = void;

if( pthread_mutexattr_init( &attr ) )
throw new SyncException( "Unable to initialize mutex" );
scope(exit) pthread_mutexattr_destroy( &attr );

if( pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE ) )
throw new SyncException( "Unable to initialize mutex" );

if( pthread_mutex_init( &m_hndl, &attr ) )
throw new SyncException( "Unable to initialize mutex" );
}
m_proxy.link = this;
Expand Down Expand Up @@ -177,35 +185,13 @@ class Mutex :
}


version( Posix )
{
shared static this()
{
int rc = pthread_mutexattr_init( &sm_attr );
assert( !rc );

rc = pthread_mutexattr_settype( &sm_attr, PTHREAD_MUTEX_RECURSIVE );
assert( !rc );
}


shared static ~this()
{
int rc = pthread_mutexattr_destroy( &sm_attr );
assert( !rc );
}
}


private:
version( Win32 )
{
CRITICAL_SECTION m_hndl;
}
else version( Posix )
{
__gshared pthread_mutexattr_t sm_attr;

pthread_mutex_t m_hndl;
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/sync/semaphore.d
Expand Up @@ -493,8 +493,8 @@ version( unittest )
{
waiting = true;
}
alertedOne = semReady.wait( 10_000_000 ); // 100ms
alertedTwo = semReady.wait( 10_000_000 ); // 100ms
alertedOne = semReady.wait( dur!"msecs"(200) );
alertedTwo = semReady.wait( dur!"msecs"(200) );
}

auto thread = new Thread( &waiter );
Expand Down
47 changes: 39 additions & 8 deletions src/core/thread.d
Expand Up @@ -33,9 +33,14 @@ version = StackGrowsDown;
*/
class ThreadException : Exception
{
this( string msg )
this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null)
{
super( msg );
super(msg, file, line, next);
}

this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__)
{
super(msg, file, line, next);
}
}

Expand All @@ -45,15 +50,22 @@ class ThreadException : Exception
*/
class FiberException : Exception
{
this( string msg )
this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null)
{
super( msg );
super(msg, file, line, next);
}

this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__)
{
super(msg, file, line, next);
}
}


private
{
import core.sync.mutex;

//
// from core.memory
//
Expand Down Expand Up @@ -1577,9 +1589,21 @@ private:
//
// All use of the global lists should synchronize on this lock.
//
static Object slock()
static Mutex slock()
{
return Thread.classinfo;
static Mutex m = null;

if( m !is null )
return m;
else
{
auto ci = Mutex.classinfo;
auto p = malloc( ci.init.length );
(cast(byte*) p)[0 .. ci.init.length] = ci.init[];
m = cast(Mutex) p;
m.__ctor();
return m;
}
}


Expand Down Expand Up @@ -2105,6 +2129,11 @@ extern (C) void thread_joinAll()

foreach( t; Thread )
{
if( !t.isRunning )
{
Thread.remove( t );
continue;
}
if( !t.isDaemon )
{
nonDaemon = t;
Expand Down Expand Up @@ -2338,7 +2367,8 @@ extern (C) void thread_suspendAll()
suspend( Thread.getThis() );
return;
}
synchronized( Thread.slock )

Thread.slock.lock();
{
if( ++suspendDepth > 1 )
return;
Expand Down Expand Up @@ -2462,7 +2492,8 @@ body
resume( Thread.getThis() );
return;
}
synchronized( Thread.slock )

scope(exit) Thread.slock.unlock();
{
if( --suspendDepth > 0 )
return;
Expand Down
1 change: 1 addition & 0 deletions src/object_.d
Expand Up @@ -1328,6 +1328,7 @@ class Exception : Throwable
{
super(msg, file, line, next);
}

this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__)
{
super(msg, file, line, next);
Expand Down

1 comment on commit 1449d7b

@braddr
Copy link
Member

@braddr braddr commented on 1449d7b Feb 3, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This submit seems to be breaking the windows build due to:
src\core\thread.d(1601): Error: undefined identifier malloc

Please sign in to comment.