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:
On Wednesday, 30 August 2017 at 10:13:57 UTC, Timothy Foster wrote:
I'm not sure if this is a known issue, or if I just don't understand how to use threads, but I've got writeln statements sometimes printing out twice in some areas of my code.
<...>
Does anyone know what is causing this or how I can fix it?

Difficult to say by what you posted.

You may want to provide a complete example so that others may try to reproduce it. Additionally, as you gradually simplify your code until it is small enough to post here, or on DPaste, you may find the cause faster yourself.

Ivan Kazmenko.

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 ?

Reply via email to