[Issue 18359] New: writeln and synchronized classes don't sync properly

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Feb 2 23:21:30 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18359

          Issue ID: 18359
           Summary: writeln and synchronized classes don't sync properly
           Product: D
           Version: D2
          Hardware: x86_64
               URL: http://dlang.org/
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P3
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: weltensturm at gmail.com

Created attachment 1679
  --> https://issues.dlang.org/attachment.cgi?id=1679&action=edit
Synchronized fails

Using this code:

import
    core.thread,
    std.stdio,
    std.range,
    std.algorithm;

void main(){
    Thread[] threads;
    iota(0,20).each!((i){
        threads ~= new Thread({
            writeln(i);
        });
    });
    foreach(t; threads)
        t.start;
    foreach(t; threads)
        t.join;
}

writeln gets confused, printing this:
0

2
3
3
4
5
5
6
7
8
8
9
10
11
12
13
14
14
15
16
18
19
17

It works fine with LDC2.


Additionally, when running the following through a Visual Studio Code terminal:

while(true)
    writeln("something");

(using code-d, I think it embeds a PowerShell) writeln breaks with an access
violation:

>[error] object.Error@(0): Access Violation
>----------------
>0x0053FA35 in write
>0x00539FF5 in fflush
>0x0046A9EA in @safe void std.stdio.File.LockingTextWriter.put!(char).put(char) at src\phobos\std\stdio.d(2876)
>0x00435867 in @safe void std.range.primitives.doPut!(std.stdio.File.LockingTextWriter, char).doPut(ref std.stdio.File.LockingTextWriter, ref char) at src\phobos\std\range\primitives.d(287)
>...


It also looks like synchronized class does not synchronize method bodies
correctly. I couldn't get a small example to fail, but I'll attach 180 lines
that do. It works when building with LDC or wrapping the method bodies in
synchronized(this){...}. (It also shows writeln going crazy)


Using Windows 10 x64, DMD32 v2.078.1, building with dub and rdmd

--


More information about the Digitalmars-d-bugs mailing list