Skip to content

Commit

Permalink
Changed thisTid to construct a MessageBox if one doesn't exist (true …
Browse files Browse the repository at this point in the history
…for the main thread and threads created with core.thread instead of spawn). This eliminates a double construction for spawned threads or the alternative of a segfault when sending to a thread not created by spawn.
  • Loading branch information
complexmath committed Jan 3, 2011
1 parent 1f6a5f3 commit ecc7390
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions std/concurrency.d
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,23 @@ private

static this()
{
mbox = new MessageBox;
// NOTE: thisTid will construct a new MessageBox if one doesn't exist,
// which should only be true of the main thread and threads created
// via core.thread instead of spawn.
}


static ~this()
{
mbox.close();
auto me = thisTid;
foreach( tid; links.keys )
_send( MsgType.linkDead, tid, me );
if( owner != Tid.init )
_send( MsgType.linkDead, owner, me );
if( mbox !is null )
{
mbox.close();
auto me = thisTid;
foreach( tid; links.keys )
_send( MsgType.linkDead, tid, me );
if( owner != Tid.init )
_send( MsgType.linkDead, owner, me );
}
}


Expand Down Expand Up @@ -289,6 +294,9 @@ private:
*/
@property Tid thisTid()
{
if( mbox )
return Tid( mbox );
mbox = new MessageBox;
return Tid( mbox );
}

Expand Down

1 comment on commit ecc7390

@WalterBright
Copy link
Member

Choose a reason for hiding this comment

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

This commit causes breakage, see http://d.puremagic.com/issues/show_bug.cgi?id=5537

Please sign in to comment.