On Sunday, 14 February 2016 at 22:54:36 UTC, Brother Bill wrote:

Please provide full replacement of this toy program that works with D version 2.070.0

This one works fine for me in Windows with VisualD and DMD 2.070.0:
------------------------------
import std.concurrency, std.stdio, std.exception;

void main() {
        auto low = 0,
                high = 100;
        auto tid = spawn(&writer);

        foreach (i; low .. high) {
                writeln("Main thread: ", i);
                tid.send(thisTid, i);
                enforce(receiveOnly!Tid() == tid);
        }
}

void writer() {
        scope(failure) return;
        for (;;) {
                auto msg = receiveOnly!(Tid, int)();
                writeln("secondary thread: ", msg[1]);
                msg[0].send(thisTid);
        }
}

------------------------------

Just one line added to writer() in order to catch OwnerTerminated exception and end the thread silently. Original version produced an error when main thread finished before the writer thread.

Reply via email to