Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REG 2.073.2] double print to stdout when reading stdin in another thread #10262

Open
dlangBugzillaToGithub opened this issue Aug 31, 2017 · 4 comments
Labels
Arch:x86 Issues specific to x86 OS:Windows Issues Specific to Windows Severity:Regression Issues that are regressions/PRs that fix regressions

Comments

@dlangBugzillaToGithub
Copy link

gassa (@GassaFM) reported this on 2017-08-31T13:40:19Z

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

CC List

Description

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
@dlangBugzillaToGithub
Copy link
Author

bugzilla (@WalterBright) commented on 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.

@dlangBugzillaToGithub
Copy link
Author

ag0aep6g commented on 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.

@dlangBugzillaToGithub
Copy link
Author

code (@MartinNowak) commented on 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.

@dlangBugzillaToGithub
Copy link
Author

r.sagitario commented on 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.

@LightBender LightBender removed the P1 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch:x86 Issues specific to x86 OS:Windows Issues Specific to Windows Severity:Regression Issues that are regressions/PRs that fix regressions
Projects
None yet
Development

No branches or pull requests

2 participants