Correct way to spawn many and stoping when one finishes ?
klimp via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Apr 10 00:48:51 PDT 2016
Is this corrrect ? Each task searches for the same thing so when
once has found the others don't need to run anymore. It looks a
bit strange not to stop those who havent find the thing:
import std.concurrency, core.thread, std.random;
void task()
{
size_t i;
while (true)
{
Thread.sleep(dur!"nsecs"(rndGen.front / 100));
++i;
rndGen.popFront;
if (i == 100)
{
send(ownerTid, true);
break;
}
}
}
void main()
{
Tid s0 = spawn(&task);
Tid s1 = spawn(&task);
//...
Tid sN = spawn(&task);
receiveOnly!bool;
}
More information about the Digitalmars-d-learn
mailing list