[Issue 16057] [TDPL] synchronized (a, b) compiles and runs with wrong semantics

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun May 22 05:48:13 PDT 2016


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

--- Comment #1 from Andrei Alexandrescu <andrei at erdani.com> ---
Test code (thanks Steve Schveighoffer) should not print "oops!" but does:


import std.concurrency;
import core.sync.mutex;
import core.thread;
import std.stdio;

__gshared Mutex a;
__gshared Mutex b;

shared static this()
{
    a = new Mutex;
    b = new Mutex;
}

void badThread()
{
    synchronized(a)
    {
        writeln("a is locked!");
        while(1) { Thread.sleep(1.seconds); }
    }
}

void main()
{
    spawn(&badThread);
    Thread.sleep(1.seconds);
    synchronized(a, b)
    {
        writeln("oops!");
    }
}

--


More information about the Digitalmars-d-bugs mailing list