[dmd-concurrency] draft 4

Kevin Bealer kevinbealer at gmail.com
Tue Jan 12 23:44:39 PST 2010


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>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
> http://lists.puremagic.com/mailman/listinfo/dmd-concurrency
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/dmd-concurrency/attachments/20100113/0017d69c/attachment.htm>


More information about the dmd-concurrency mailing list