D Book page 402 Concurrency FAIL
Brother Bill via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Feb 14 14:54:36 PST 2016
In "The D Programming Language", page 402, the toy program fails.
The first fail is that enforce() needs: import std.exception;
The second fail is that when debugging, in Visual Studio 2015
Community Edition,
it fails with this error:
First-change exception: std.format.FormatException Unterminated
format specifier: "%" at
C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(830).
Please provide full replacement of this toy program that works
with D version 2.070.0
This is what was entered:
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() {
for (;;) {
auto msg = receiveOnly!(Tid, int)();
writeln("secondary thread: ", msg[1]);
msg[0].send(thisTid);
}
}
Thank you.
More information about the Digitalmars-d-learn
mailing list