On 12/2/24 7:18 AM, Salih Dincer wrote:
> On Monday, 2 December 2024 at 08:00:40 UTC, Richard (Rikki) Andrew
> Cattermole wrote:
>> You don't need both atomics an mutex's, pick one.
>
> The compiler wants us to use atomicOp; If you want, take it out of the
> synchronized(mutex) { } block, it doesn't matter:

Then use atomicOp. You don't need any mutex for this problem, especially when they can make this program very slow. Imagine how a thread will have to relinquish its execution time to wait for a mutex in order to increment a simple int. The CPU's atomic operation primitives already achieve that.

Another general reason for avoiding a mutex is that they are low level primitives, which should be needed only in special cases when existing solution that are already based on them don't work for your problem for some reason. For example, std.parallelism and std.concurrency already use features like mutexes but perhaps they can't be used for some reason.

Ali

  • Variable modifie... Ritina via Digitalmars-d-learn
    • Re: Variabl... Andy Valencia via Digitalmars-d-learn
      • Re: Var... Ali Çehreli via Digitalmars-d-learn
        • Re:... Andy Valencia via Digitalmars-d-learn
        • Re:... Salih Dincer via Digitalmars-d-learn
          • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
            • ... Salih Dincer via Digitalmars-d-learn
              • ... Ali Çehreli via Digitalmars-d-learn
              • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
                • ... Nick Treleaven via Digitalmars-d-learn
                • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
                • ... Ali Çehreli via Digitalmars-d-learn
                • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
                • ... Andy Valencia via Digitalmars-d-learn
    • Re: Variabl... Salih Dincer via Digitalmars-d-learn

Reply via email to