writeln() sometimes double prints from main() if I run a thread checking for input?

Ivan Kazmenko via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 30 06:24:55 PDT 2017


On Wednesday, 30 August 2017 at 10:55:20 UTC, Timothy Foster 
wrote:
> 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){}
> }

I also cannot reproduce this.

My current system is Win7 64-bit.  I tried 32-bit dmd 2.072.0 and 
2.075.1, with optimizations turned on and off, but it prints 
correctly tens of times in each case.

Try running the program in a bare console (cmd.exe on Windows, or 
some *sh on Linux).  If the problem goes away, your usual 
environment is likely at fault.  If not,.. well, no idea for now.

Ivan Kazmenko.



More information about the Digitalmars-d-learn mailing list