digitalmars.D.learn - D Book page 402 Concurrency FAIL
- Brother Bill (30/30) Feb 14 2016 In "The D Programming Language", page 402, the toy program fails.
- cym13 (3/6) Feb 14 2016 Can't reproduce with DMD 2.0.70, LDC 0.16.1 or GDC 5.3.0 on Linux
- Brother Bill (3/10) Feb 14 2016 It is failing in Windows, not Linux.
- Mike Parker (3/15) Feb 14 2016 Works for me on the command line. I don't have VisualD installed
- thedeemon (27/29) Feb 15 2016 This one works fine for me in Windows with VisualD and DMD
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.
Feb 14 2016
On Sunday, 14 February 2016 at 22:54:36 UTC, Brother Bill wrote:In "The D Programming Language", page 402, the toy program fails. [...]Can't reproduce with DMD 2.0.70, LDC 0.16.1 or GDC 5.3.0 on Linux x86_64. The code seems to work as intended.
Feb 14 2016
On Sunday, 14 February 2016 at 23:39:33 UTC, cym13 wrote:On Sunday, 14 February 2016 at 22:54:36 UTC, Brother Bill wrote:It is failing in Windows, not Linux. Can someone reproduce this in Windows with VisualD?In "The D Programming Language", page 402, the toy program fails. [...]Can't reproduce with DMD 2.0.70, LDC 0.16.1 or GDC 5.3.0 on Linux x86_64. The code seems to work as intended.
Feb 14 2016
On Monday, 15 February 2016 at 00:58:54 UTC, Brother Bill wrote:On Sunday, 14 February 2016 at 23:39:33 UTC, cym13 wrote:Works for me on the command line. I don't have VisualD installed right now, but I can't see how that would make a difference.On Sunday, 14 February 2016 at 22:54:36 UTC, Brother Bill wrote:It is failing in Windows, not Linux. Can someone reproduce this in Windows with VisualD?In "The D Programming Language", page 402, the toy program fails. [...]Can't reproduce with DMD 2.0.70, LDC 0.16.1 or GDC 5.3.0 on Linux x86_64. The code seems to work as intended.
Feb 14 2016
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.0This 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.
Feb 15 2016