Skip to content

Instantly share code, notes, and snippets.

@Crazy-Owl
Created September 10, 2014 07:15
Show Gist options
  • Save Crazy-Owl/74d7cb005d6293a3c700 to your computer and use it in GitHub Desktop.
Save Crazy-Owl/74d7cb005d6293a3c700 to your computer and use it in GitHub Desktop.
concurrent.d
import std.stdio;
import std.conv;
import std.concurrency;
void workerFunc() {
int value = 0;
value = receiveOnly!int();
while (value >= 0) {
writefln("Worker: %s received", value);
double result = to!double(value) / 5;
ownerTid.send(result);
value = receiveOnly!int();
}
}
void main() {
Tid worker = spawn(&workerFunc);
foreach(value; 1 .. 5) {
worker.send(value);
double result = receiveOnly!double();
writefln("sent: %s \nreceived: %s", value, result);
}
worker.send(-1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment