Bug 18277 – synchronized statement with comma operator ignores first arguments
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2018-01-22T11:47:05Z
Last change time
2018-01-24T15:06:11Z
Assigned to
No Owner
Creator
Simen Kjaeraas
Comments
Comment #0 by simen.kjaras — 2018-01-22T11:47:05Z
According to TDPL[1], synchronized (a, b) should should lock both a and b. This does not happen:
import std.stdio;
import core.thread;
class C {}
class MyThread1 : Thread {
C c, d;
this(C c, C d) {
this.c = c;
this.d = d;
super(&run);
}
void run() {
synchronized(c, d) {
writeln("Thread sleeping...");
Thread.sleep(5.dur!"seconds");
writeln("Thread woke up");
}
}
}
unittest {
C c = new C;
C d = new C;
auto derived = new MyThread1(c, d).start();
Thread.sleep(2.dur!"seconds");
synchronized(c) {
writeln("c is not synchronized");
}
synchronized(d) {
writeln("d is synchronized");
}
}
Expected output:
Thread sleeping...
Thread woke up
c is not synchronized
d is synchronized
Actual output:
Thread sleeping...
c is not synchronized
Thread woke up
d is synchronized
[1]: http://www.informit.com/articles/article.aspx?p=1609144&seqNum=15
Comment #1 by yebblies — 2018-01-24T15:06:11Z
*** This issue has been marked as a duplicate of issue 16057 ***