Top "Compare-and-swap" questions

Compare and swap (compare and exchange) is an atomic operation that writes a value to a memory location only if its current value is equal to a given expected value.

How Compare and Swap works

I have read quite some posts that say compare and swap guarantees atomicity, However I am still not able to …

c multithreading mutex compare-and-swap
Java Concurrency: CAS vs Locking

I'm reading the Book Java Concurrency in Practice. In chapter 15, they are talking about the nonblocking algorithms and the compare-and-swap (…

java concurrency locking compare-and-swap
Is synchronizing with `std::mutex` slower than with `std::atomic(memory_order_seq_cst)`?

The main reason for using atomics over mutexes, is that mutexes are expensive but with the default memory model for …

c++ c++11 concurrency memory-model compare-and-swap
In Java what is the performance of AtomicInteger compareAndSet() versus synchronized keyword?

I was implementing a FIFO queue of requests instances (preallocated request objects for speed) and started with using the "synchronized" …

java locking compare-and-swap
atomic swap with CAS (using gcc sync builtins)

Can the compare-and-swap function be used to swap variables atomically? I'm using C/C++ via gcc on x86_64 RedHat Linux, …

c++ gcc linked-list atomic compare-and-swap
Why isn't atomic double fully implemented

My question is quite simple. Why isn't std::atomic<double> implemented completely? I know it has to do …

c++ floating-point atomic compare-and-swap stdatomic
Is x86 CMPXCHG atomic, if so why does it need LOCK?

The Intel documentation says This instruction can be used with a LOCK prefix to allow the instruction to be executed …

concurrency x86 atomicity lock-free compare-and-swap
Java compare and swap semantics and performance

What is the semantics of compare and swap in Java? Namely, does the compare and swap method of an AtomicInteger …

java performance concurrency jvm compare-and-swap
Java Atomic Variable set() vs compareAndSet()

I want to know the difference between set() and compareAndSet() in atomic classes. Does the set() method also ensure the …

java set atomic compare-and-swap