PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchNeither compare-and-swap (CAS) nor a lock is inherently faster: the answer depends on the exact operation, contention, hardware, and implementation being compared. No reproducible record of the title’s promised first-person benchmark is available, so this article does not claim personal test results or invent a mid-test reversal. Published examples instead show why a result from one workload can mislead when treated as a universal rule.
What CAS and a lock actually do
Compare-and-swap is an atomic read-modify-write operation: it checks whether a memory location has an expected value and, if so, replaces it. In the Linux kernel, CAS is one operation in the atomic API, alongside operations such as atomic add and exchange. The API’s operations and their semantics involve architecture-specific considerations; the name of an operation alone does not tell you its cost on every processor. Linux kernel documentation: Atomic types, v6.6
As an Amazon Associate I earn from qualifying purchases.
A CAS loop adds a second layer: if the expected value no longer matches, the operation may be retried. Under contention, multiple threads can repeatedly compete to update the same location. A lock takes a different route: it coordinates access so that a thread holding the lock can perform protected work while others wait or contend for access.
That makes “CAS versus a lock” an incomplete comparison. A single CAS instruction, a retrying CAS loop, an atomic fetch-add, and a mutex-protected increment are distinct operations or algorithms. They may do different work and have different behavior under contention. Compare them only when they implement equivalent work.
#1 Best Overall
Why one result can reverse your conclusion
The cost of a CAS loop is not just the cost of one successful attempt. Failed attempts consume work, and contention affects which thread can obtain ownership of the cache line containing the shared value. A source-level atomic increment may also compile into different machine instructions on different platforms. The compiler output, runtime, lock implementation, and memory-ordering choices therefore matter alongside the source code. Travis Downs, “A Concurrency Cost Hierarchy”
Downs’s maximum-contention, single-counter comparison is a useful example of how the answer can change with the implementation being tested: atomic add was significantly faster than his CAS loop, while std::mutex was competitive on the tested Skylake setup. That is a result for that benchmark and its machines—not a general ranking of atomics and locks. Travis Downs, “A Concurrency Cost Hierarchy,” July 6, 2020
Rank #2
A different workload could change the outcome. A single shared counter forces threads to compete over the same data, making it a deliberately narrow, high-contention test. An application that protects longer or different work, uses several independent data locations, or runs on another architecture is asking a different performance question.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsWhat a published CAS benchmark example does—and does not—show
On September 30, 2026, Changbin Du proposed adding an atomic CAS benchmark to Linux perf bench. The proposal describes configurable thread and iteration counts and includes an example output. It is a mailing-list patch proposal, not evidence that the feature was accepted or released, and the figures below are example output—not an independently validated run or a comparison with a lock. Changbin Du, “[PATCH] perf bench: Add atomic CAS benchmark,” September 30, 2026
| Proposal example detail | Value |
|---|---|
| Threads | 2 |
| Iterations per thread | 100,000,000 |
| Repeats and warmup | 10 repeats after 1 warmup run |
| Average wall-clock time | 7,365.480 milliseconds; standard deviation 66.014 milliseconds |
| Total throughput | 27,153,697 operations per second |
The proposal’s benchmark synchronizes thread starts, uses a shared cache-line-aligned counter, excludes an initial warmup run, and reports aggregate and per-thread results. Those are useful measurement details, but a CAS-only example cannot answer whether CAS beats a lock: it does not provide an equivalent lock run under the same conditions.
How to make the comparison fair
Before timing, define the question precisely: which implementation completes the same protected task most efficiently for the workload you care about? A useful report makes the relevant conditions visible rather than presenting a bare time or throughput number.
- Operation and algorithm: State whether the test uses one CAS attempt, a retrying CAS loop, an atomic fetch-add, or an increment protected by a named lock type. Ensure each version performs equivalent work.
- Workload and contention: Describe the protected work, number of threads, and whether the test is single-threaded, lightly contended, or heavily contended. A shared counter is not a stand-in for every application’s critical section.
- Platform and memory system: Name the processor and architecture, and explain relevant placement and sharing conditions, including cache behavior, alignment, operand size, and NUMA placement where applicable.
- Implementation: Record the language, compiler and runtime, lock implementation, and memory-ordering choices. When possible, inspect the generated machine code instead of assuming that similar source expressions become the same instructions.
- Measurement: Explain how threads begin, whether there is a warmup, how many trials are repeated, and whether results are wall-clock time, throughput, or both. Include variability and per-thread results where available; an aggregate can conceal uneven progress.
These details matter because atomic operations do not have one fixed performance relationship across processors. ETH Zurich’s SPCL project reports that “All the tested atomics have usually comparable latency and bandwidth,” referring to the operations and architectures evaluated in that study—not all processors or applications. ETH Zurich SPCL, “What is the true cost/performance of atomic operations?”
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Choose for correctness first, then measure the real work
Performance is only one reason to choose an approach. CAS can serve as a basis for synchronization and lock-free algorithms, but building more elaborate operations on it can introduce complexity, scalability, and performance costs. Paul E. McKenney, Is Parallel Programming Hard, And, If So, What Can You Do About It?, version 2024.12.27a
Best Value
Use a lock when it gives the clearest correct way to protect the shared state; use an atomic operation or CAS-based design when its semantics fit the problem. Then benchmark the real critical section on the target system. A counter microbenchmark can reveal costs under its own conditions, but it cannot establish a universal winner—or predict every application’s result.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




