Created attachment 1679
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
Comment #1 by robert.luger — 2018-02-02T23:31:45Z
Tried it with --arch=x86_64/-m64, does not happen there. Only seems to affect 32 bit binaries.
Comment #2 by robert.schadek — 2024-12-13T18:56:37Z