synchronized class bugs?

IGotD- nise at nise.com
Tue Apr 7 16:33:13 UTC 2020


On Tuesday, 7 April 2020 at 16:18:53 UTC, Gregor Mückl wrote:
> 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.

I think this is correct, you should be allowed to cast to atomics 
or do whatever operation you want within the mutex, atomic 
operation or not.

The wrong result sound more like a bug in the locking itself. One 
way is to try this is on another operating system and see if you 
get similar result.


More information about the Digitalmars-d mailing list