# atomicCas

`import { atomicCas } from "destack:sync";`

Atomic compare-and-swap.

Atomically compares the value at `ptr` with `expected`.
If equal, stores `desired` and returns `[oldValue, true]`.
If not equal, returns `[currentValue, false]`.

```ds title="atomicCas"
export declare function atomicCas<T>(ptr: *T, expected: T, desired: T, order: MemoryOrdering, scope: AtomicScope, memoryScope: MemoryScope, regions: MemoryRegionSet, isVolatile: boolean, isMakeAvailable: boolean, isMakeVisible: boolean): (T, boolean)
```

[language/library/src/sync/atomic.ds:236:247](https://github.com/destack-sh/destack/blob/main/language/library/src/sync/atomic.ds#L236-L247)
