[dmd-concurrency] draft 4

Sean Kelly sean at invisibleduck.org
Tue Jan 12 15:04:48 PST 2010


On Jan 12, 2010, at 12:51 PM, Robert Jacques wrote:
> 
> I know this is a bit of a bike shed, but I'd prefer something shorter for receiveOnly, (like recv or receive) as A) type-checked message passing should be the easy/default way to do things and B) it's easy to define recv!()() to return the unchecked message using a variant. I'd also like to be able to use recv(tid,i); in addition to recv!(Tid, int)(); but I haven't been able to get the templates to not clash with each other.

In my sample message passing implementation I use these prototypes:

    void sendmsg(T...)( Pid pid, T vals );
    void recvmsg(T...)( T ops );

Sample call:

    sendmsg( pid, 2, "hi" );
    ...
    recvmsg( (MyStruct s) {},
                     (int a, string b) { writefln( "got %s, %s", a, b ); } );

I guess an explicit receive prototype would be:

    auto val = recvtype!T();

That could be translated to:

    T recvtype(T)()
    {
        T ret;
        recvmsg( (T val) { ret = val; },
                          (Variant val) { throw new Exception( "unexpected value" ); } );
        return ret;
    }

Not sure if it would be possible to use the same function name for both, though because the effect is so different you may really want different names anyway.


More information about the dmd-concurrency mailing list