C++ Logo


Advanced search

Re: atomic_swap()

From: Thiago Macieira <thiago_at_[hidden]>
Date: Fri, 16 Jul 2021 11:40:15 -0700
On Friday, 16 July 2021 11:28:46 PDT Phil Bouchard via Std-Proposals wrote:
> I just realized that swap() is not using the XCHG assembly instruction
> at all. Maybe adding an atomic_swap() could achieve this?

No, that won't work. You can't atomically swap two memory locations.

If only one of the two variables needs to be atomically swapped, we already
have a function for that, atomic_exchange().

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DPG Cloud Engineering

Received on 2021-07-16 13:40:21