Bug 17797 – [REG 2.073.2] double print to stdout when reading stdin in another thread

Status
NEW
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2017-08-31T13:40:19Z
Last change time
2024-12-01T16:30:44Z
Assigned to
No Owner
Creator
Ivan Kazmenko
Moved to GitHub: phobos#10262 →

Comments

Comment #0 by gassa — 2017-08-31T13:40:19Z
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.
Comment #3 by code — 2017-10-09T11:26:58Z
cat > bug.d << CODE import std.stdio, core.thread; void main() { auto thread = new Thread(&func).start; writeln("Output"); writeln("Output2"); writeln("Output3"); thread.join(); } void func() { foreach (line; stdin.byLineCopy) { } } CODE dmd -run bug.d ---- Slightly nicer version that terminates on EOF (Ctrl+D), works as expected on linux. Sure about 2.073.2? The only interesting change in https://github.com/dlang/dmd/compare/v2.073.1...v2.073.2 https://github.com/dlang/druntime/compare/v2.073.1...v2.073.2 https://github.com/dlang/phobos/compare/v2.073.1...v2.073.2 is https://github.com/dlang/dmd/pull/6582.
Comment #4 by r.sagitario — 2017-10-10T07:03:15Z
I could verify it happens with 2.073.2, but not 2.073.1. This is caused by an updated snn.lib. Might be introduced by the fix for issue 13727.
Comment #5 by robert.schadek — 2024-12-01T16:30:44Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10262 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB