Consider the following program:
-----
import std.stdio, core.thread;
void main(){
auto thread = new Thread(&func).start;
writeln("Output");
writeln("Output2");
writeln("Output3");
while(true){}
}
void func(){
foreach(line; stdin.byLineCopy){}
}
-----
The correct output is:
-----
Output
Output2
Output3
-----
This starts a thread to read from stdin, and then writes several lines to stdout in the main thread and enters and infinite loop.
When compiled with dmd 2.073.1 or earlier, everything is fine.
Starting from dmd 2.073.2, the output is unstable but usually not correct.
Locally, I usually observe the following output:
-----
Output
Output2
Output3
Output2
-----
Or sometimes:
-----
Output
Output2
Output2
Output3
-----
Here are the steps to reproduce, tested on 64-bit Windows with a 32-bit compiler.
1. Use dmd 2.073.2 or later.
2. Compile like "dmd program.d" (compiler switches don't seem to matter).
3. Run a command prompt, like "cmd.exe".
4. Execute "program.exe" (importantly, without any I/O redirection).
Original thread at D.Learn:
https://forum.dlang.org/post/[email protected]
Comment #1 by bugzilla — 2017-10-03T08:39:15Z
It happens on Win32 as well, which uses the DMC runtime library, not Microsoft's. So it is not specific to the Microsoft runtime library.
I suspect it is a Phobos problem, not a compiler issue, and changed the category accordingly.
Comment #2 by ag0aep6g — 2017-10-03T09:16:11Z
(In reply to Walter Bright from comment #1)
> It happens on Win32 as well, which uses the DMC runtime library, not
> Microsoft's. So it is not specific to the Microsoft runtime library.
It *only* happens with the DMC runtime. People are running 64-bit Windows, but they're not using 64-bit dmd. I just tested in a virtual machine with -m32mscoff and didn't see duplicated lines.