If you start the worker with spawnLinked then you will receive
a LinkTerminated message.
import std.stdio;
import std.concurrency;
import core.thread;
void main()
{
auto worker = spawnLinked(&workerFunc);
// Wait for worker to terminate
bool terminated = false;
while (!terminated) {
writeln("Waiting for the worker to terminate...");
terminated = receiveTimeout(1.seconds,
(LinkTerminated e) {
if (e.tid == worker) {
writefln("Terminated");
}
}
);
}
}
void workerFunc()
{
Thread.sleep(3.seconds);
}
Ali
But this is another spawned process. How can I tell this second
process to wait on the first one.
eg:
auto processA = spawnLinked(funcA);
auto processB = spawnLinked(funcB);
funcA()
{
doSomething();
}
funcB()
{
doSomething();
// wait for A
doSomethingElse();
}
This is a simplified example, the real case two process would be
spawned irrespective to each other. the second process could may
also be launched by when the first is already done.