[dmd-concurrency] draft 4

Robert Jacques sandford at jhu.edu
Tue Jan 12 12:51:05 PST 2010


On Tue, 12 Jan 2010 03:45:35 -0500, Andrei Alexandrescu  
<andrei at erdani.com> wrote:
> To be found at the usual location:
>
> http://erdani.com/d/fragment.preview.pdf
>
> I didn't add a lot of text this time around but I do have a full example  
> of communicating threads. Skip to the last section for explanation. I  
> paste the code below. I think it looks pretty darn cool. Sean, please  
> let me know if it floats your boat.
>
> import std.concurrency, std.stdio;
>
> void main() {
>     auto low = 0, high = 1000;
>     auto tid = spawn(&fun);
>     foreach (i; low .. high) {
>        writeln("Main thread: ", message, i);
>        tid.send(thisTid, i);
>        enforce(receiveOnly!Tid() == tid);
>     }
>     // Signal the other thread
>     tid.send(Tid(), 0);
> }

message is undefined and doesn't match the output. Is this a typo?

> void fun() {
>     for (;;) {
>        auto msg = receiveOnly!(Tid, int)();
>        if (!msg[0]) return;
>        writeln("Secondary thread: ", msg[1]);
>        msg[0].send(thisTid);
>     }
> }
>
>
> Andrei
> _______________________________________________
> dmd-concurrency mailing list
> dmd-concurrency at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-concurrency

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.


More information about the dmd-concurrency mailing list