[dmd-concurrency] draft 4

Andrei Alexandrescu andrei at erdani.com
Tue Jan 12 16:14:18 PST 2010


Sean Kelly wrote:
> On Jan 12, 2010, at 2:16 PM, Andrei Alexandrescu wrote:
> 
>> Sean Kelly wrote:
>>
>>> What I'd like to do now that I haven't been able to because of a compiler bug is allow a timeout and catchall receiver to be supplied to the full recvmsg call:
>>> recvmsg( after(5, { writefln( "no message received!" ); },
>>>                  any( (Variant v) { writefln( "got something: %s", v ); } ) );
>> This is cute, perhaps a bit too cute. My objections are many but minor:
>>
>> * "recvmsg" is an awful name that evokes to me the name of a Cobol routine. It's very difficult to use in a conversation, and my accent doesn't help either :o). I think "receive" is a definite improvement.
> 
> Fine with me.  I originally chose recvmsg and sendmsg to try and avoid name collisions.  I'd be just as happy with send and receive or whatever else instead.
> 
>> * Instead of after(...) as a clause, I'd rather have a receiveTimed (or recvmsgtmd if you wish) that takes a timeout value and returns true or false. I mean I'm not sure what moving the timeout code inside the call to recvms... I mean receive  would gain us.
> 
> Nothing really.  I was mostly trying to model the Erlang pattern matching style as closely as possible.  Seems like it might be annoying to try and prevent:
> 
>     receive( after(5, ...), after(10, ...) );
> 
> anyway, assuming we wanted to be that strict.  Note that when multiple functions are passed, the match is found via a nested loop:
> 
>     foreach( m; messages ) {
>         foreach( f; functions ) {
>             if( matches( m, f ) ) {
>                 f( m );
>                 removeMessage( m );
>                 return;
>             }
>         }
>     }
> 
> so passing multiple functions that accept the same params is valid.  The first will just always get the message.

I see. It would be great to prevent such masking during compilation.

Andrei



More information about the dmd-concurrency mailing list