Re: D Book page 402 Concurrency FAIL

2016-02-15 Thread thedeemon via Digitalmars-d-learn

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();

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.


Re: D Book page 402 Concurrency FAIL

2016-02-14 Thread Mike Parker via Digitalmars-d-learn

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:
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.


It is failing in Windows, not Linux.
Can someone reproduce this in Windows with VisualD?


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.


Re: D Book page 402 Concurrency FAIL

2016-02-14 Thread Brother Bill via Digitalmars-d-learn

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:
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.


It is failing in Windows, not Linux.
Can someone reproduce this in Windows with VisualD?


Re: D Book page 402 Concurrency FAIL

2016-02-14 Thread cym13 via Digitalmars-d-learn

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.


D Book page 402 Concurrency FAIL

2016-02-14 Thread Brother Bill via Digitalmars-d-learn

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();

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.