[dmd-concurrency] draft 4

Andrei Alexandrescu andrei at erdani.com
Tue Jan 12 23:47:10 PST 2010


Yah, it was mentioned and fixed. Thanks.

Andrei

Kevin Bealer wrote:
> In this line from 'main()', I think 'message' here is a cut n' paste 
> stowaway?
> 
> writeln("Main thread: ", message, i);
> 
> Kevin
> 
> On Tue, Jan 12, 2010 at 3:45 AM, Andrei Alexandrescu <andrei at erdani.com 
> <mailto: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);
>     }
> 
>     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 <mailto:dmd-concurrency at puremagic.com>
>     http://lists.puremagic.com/mailman/listinfo/dmd-concurrency
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> dmd-concurrency mailing list
> dmd-concurrency at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-concurrency


More information about the dmd-concurrency mailing list