In this line from 'main()', I think 'message' here is a cut n' paste stowaway?<br><br>writeln("Main thread: ", message, i);<br><br>Kevin<br><br><div class="gmail_quote">On Tue, Jan 12, 2010 at 3:45 AM, Andrei Alexandrescu <span dir="ltr"><<a href="mailto:andrei@erdani.com">andrei@erdani.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">To be found at the usual location:<br>
<br>
<a href="http://erdani.com/d/fragment.preview.pdf" target="_blank">http://erdani.com/d/fragment.preview.pdf</a><br>
<br>
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.<br>
<br>
import std.concurrency, std.stdio;<br>
<br>
void main() {<br>
auto low = 0, high = 1000;<br>
auto tid = spawn(&fun);<br>
foreach (i; low .. high) {<br>
writeln("Main thread: ", message, i);<br>
tid.send(thisTid, i);<br>
enforce(receiveOnly!Tid() == tid);<br>
}<br>
// Signal the other thread<br>
tid.send(Tid(), 0);<br>
}<br>
<br>
void fun() {<br>
for (;;) {<br>
auto msg = receiveOnly!(Tid, int)();<br>
if (!msg[0]) return;<br>
writeln("Secondary thread: ", msg[1]);<br>
msg[0].send(thisTid);<br>
}<br>
}<br>
<br>
<br>
Andrei<br>
_______________________________________________<br>
dmd-concurrency mailing list<br>
<a href="mailto:dmd-concurrency@puremagic.com" target="_blank">dmd-concurrency@puremagic.com</a><br>
<a href="http://lists.puremagic.com/mailman/listinfo/dmd-concurrency" target="_blank">http://lists.puremagic.com/mailman/listinfo/dmd-concurrency</a><br>
</blockquote></div><br>