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

Timothy Foster via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 30 04:40:33 PDT 2017


On Wednesday, 30 August 2017 at 11:28:49 UTC, Stefan Koch wrote:
> On Wednesday, 30 August 2017 at 10:55:20 UTC, Timothy Foster 
> wrote:
>> On Wednesday, 30 August 2017 at 10:44:43 UTC, Ivan Kazmenko 
>> 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){}
>> }
>>
>> The printout from the above typically gives me:
>> Output
>> Output2
>> Output2
>> Output3
>>
>> I've narrowed down the issue. I just don't know what to do 
>> about it.
>
> I cannot reproduce this. what os / compiler are you using ?

Windows 7 Ultimate 64-bit
DMD32 D Compiler v2.075.1

The issue is inconsistent. Sometimes it'll print as it should, 
sometimes it'll double the first line, sometimes the second, 
sometimes both the first and second.


More information about the Digitalmars-d-learn mailing list