synchronized class bugs?

Gregor Mückl gregormueckl at gmx.de
Tue Apr 7 16:18:53 UTC 2020


On Tuesday, 7 April 2020 at 16:11:12 UTC, IGotD- wrote:
> Correct me if I'm wrong, aren't all synchronized classes 
> protected with a mutex. In this case atomic operations are 
> pointless as all methods are protected by the mutex anyway.

That's what's I'm trying to say. They should be protected and the 
code for locking and unlocking is generated (tested on dmd, gdc 
and ldc). But

- the compiler tries to enforce atomics in this context anyway, 
but they are pointless due to the mutex
- the mutex doesn't lead to proper locking behavior at runtime; 
when calling increment an decrement in many threads in parallel, 
the result is wrong.




More information about the Digitalmars-d mailing list