4 ms·
almost like erlang (http://dlang.org/ http://dlang.org/) import std.stdio; import std.concurrency; void world() { bool running = true; while (ru
by gizmomogwai 14y ago
almost like erlang (http://dlang.org/ http://dlang.org/)
import std.stdio;
import std.concurrency;
void world() {
bool running = true;
while (running) {
receive(
(Tid finished) { writeln("World"); send(finished, true); },
(OwnerTerminated e) { running = false; }
);
}
}
void hello(Tid world, Tid finished) {
for (int i=0; i<1000; i++) {
write("Hello ");
send(world, thisTid);
receiveOnly!(bool)();
}
send(finished, true);
}
int main(string[] args) {
auto world = spawn(&world);
auto hello = spawn(&hello, world, thisTid);
receiveOnly!(bool)();
return 0;
}