www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - synchronized with multiple arguments

reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
A reader reminded me (thanks!) that in TDPL synchronized with multiple 
argument does the right thing - locks objects in increasing order of 
address.

So now to everyone's unpleasant surprise, the sample code in TDPL 
compiles and runs, it just has difficult to detect problems.

So regardless of the discussion of the comma operator, synchronized with 
multiple arguments should just work.

Is synchronized being lowered to some function calls?


Andrei
May 13 2016
parent ZombineDev <petar.p.kirov gmail.com> writes:
On Friday, 13 May 2016 at 09:17:06 UTC, Andrei Alexandrescu wrote:
 A reader reminded me (thanks!) that in TDPL synchronized with 
 multiple argument does the right thing - locks objects in 
 increasing order of address.

 So now to everyone's unpleasant surprise, the sample code in 
 TDPL compiles and runs, it just has difficult to detect 
 problems.

 So regardless of the discussion of the comma operator, 
 synchronized with multiple arguments should just work.
+1
 Is synchronized being lowered to some function calls?
Here's the relevant code: https://github.com/dlang/dmd/blob/master/src/statement.d#L4974 IIUC, the code assumes that there is a single object that needs to be locked. Which is definitely wrong. BTW, should synchronized (obj) allow calling non-shared methods of obj inside the block?
May 13 2016