# atomicExchange

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

Atomic exchange.

Atomically replaces the value at `ptr` with `value`.
Returns the previous value.

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

[language/library/src/sync/atomic.ds:271:281](https://github.com/destack-sh/destack/blob/main/language/library/src/sync/atomic.ds#L271-L281)
