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
Thu Aug 31 14:06:17 PDT 2017


On Thursday, 31 August 2017 at 14:43:39 UTC, Steven Schveighoffer 
wrote:
> Just a thought, but the "double printing" could be a 
> misunderstanding. It could be printing Output\nOutput2, but not 
> getting the 2 out there.

No no, it's four lines instead of three.  If we change the lines 
to disjoint sets of letters, the problem persists.

> Note that DMD 32-bit is using DMC libc. It might be that it 
> gets hung up somehow when expecting input, like it locks the 
> console somehow.
>
> I would say that byLineCopy puts the thread to sleep waiting 
> for input, and it doesn't get out of that state. So it could be 
> that the bug only appears when it gets to that state at some 
> point in the output. I'd pepper some sleeps around the outputs 
> to see if you can make the context switches more predictable.

Inserting different sleeps into the threads makes the problem go 
away (cannot reproduce).  Inserting identical sleeps produces the 
error with roughly the same probability.

Anyway, I've reported it 
(https://issues.dlang.org/show_bug.cgi?id=17797), along with a 
more or less exact version (2.073.2) where the problem was 
introduced.

Ivan Kazmenko.



More information about the Digitalmars-d-learn mailing list