import std.concurrency, std.stdio, std.exception;
void main() {
auto tid = spawn(&writer);
foreach (i; 0..1000) {
writeln("main thread: ", i);
tid.send(thisTid, i);
enforce(receiveOnly!Tid() == tid);
}
}
void writer() {
for (;;) {
auto msg = receiveOnly!(Tid, int)();
writeln("Child thread: ", msg[1]);
msg[0].send(thisTid);
}
}