www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17797] New: [REG 2.073.2] double print to stdout when reading

https://issues.dlang.org/show_bug.cgi?id=17797

          Issue ID: 17797
           Summary: [REG 2.073.2] double print to stdout when reading
                    stdin in another thread
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: gassa mail.ru

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/ozbhjgvqmurphkeosrpf forum.dlang.org

--
Aug 31