import std concurrency std stdio std exception void main auto tid spaw

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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);
}
}