[phobos] Typo (bug) in std.concurrency

Sean Kelly sean at invisibleduck.org
Wed Jun 30 21:37:07 PDT 2010


On Jun 30, 2010, at 9:10 PM, Lars Tandle Kyllingstad wrote:

> I hate to be the one throwing all these problems at you, but here's
> another one.  The following compiles and runs without error:
> 
>        import std.concurrency;
> 
>        void foo(int i) { }
> 
>        void main()
>        {
>                spawn(&foo);
>                spawn(&foo, "hello world");
>                spawn(&foo, "hello world", 3.14);
>        }
> 
> Basically, it seems you can pass any set of parameters to spawn().  They
> don't have to match foo()'s.  Note that a thread does indeed get spawned
> in all of the cases above, and the parameter i contains a nonsense
> value.

That doesn't make any sense.  Here's the code for spawn:

private Tid spawn_(T...)( bool linked, void function(T) fn, T args )
{
    // TODO: MessageList and &exec should be shared.
    auto spawnTid = Tid( new MessageBox );
    auto ownerTid = thisTid;

    void exec()
    {
        mbox  = spawnTid.mbox;
        owner = ownerTid;
        fn( args );
    }

    auto t = new Thread( &exec ); t.start();
    links[spawnTid] = linked;
    return spawnTid;
}

Why would it compile if the wrong args were supplied?  Can someone confirm this is a compiler bug?


More information about the phobos mailing list