synchronized class bugs?
Gregor Mückl
gregormueckl at gmx.de
Tue Apr 7 23:34:13 UTC 2020
On Tuesday, 7 April 2020 at 16:33:13 UTC, IGotD- wrote:
> 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.
>
I don't think you understand: the compiler actively prohibits the
use of non-atomic operations in synchronized functions. That
makes no sense.
> 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.
The results are wrong with dmd 2.088 on Windows and dmd 2.91, gdc
9.3.0 and ldc 1.20.1 on Linux.
More information about the Digitalmars-d
mailing list