---
name: "qb_atomic_int_compare_and_exchange"
section: "3"
platform: "linux"
package: "libqb"
version: "2.0.10-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/qb_atomic_int_compare_and_exchange"
---

# qb\_atomic\_int\_compare\_and\_exchange(3)

Compares oldval with the integer pointed to by atomic and if they are equal, atomically exchanges \*atomic with newval.

## NAME

qb\_atomic\_int\_compare\_and\_exchange - Compares oldval with the integer pointed to by atomic and if they are equal, atomically exchanges \*atomic with newval.

## SYNOPSIS

```
#include <qb/qbatomic.h>

int32_t qb_atomic_int_compare_and_exchange(
    volatile int32_t QB_GNUC_MAY_ALIAS   *atomic,  /* a pointer to an integer */
    int32_t                               oldval,  /* the assumed old value of *atomic */
    int32_t                               newval   /* the new value of *atomic*/
);
```

## PARAMS

**atomic** *a pointer to an integer*

**oldval** *the assumed old value of \*atomic*

**newval** *the new value of \*atomic*

## DESCRIPTION

Also acts as a memory barrier.

## RETURN VALUE

QB\_TRUE, if \*atomic was equal oldval. QB\_FALSE otherwise.

## SEE ALSO

[*qb\_atomic\_int\_set*(3)](/qb_atomic_int_set/3.md), [*qb\_atomic\_int\_get*(3)](/qb_atomic_int_get/3.md), [*qb\_atomic\_int\_add*(3)](/qb_atomic_int_add/3.md), [*qb\_atomic\_init*(3)](/qb_atomic_init/3.md), [*qb\_atomic\_pointer\_get*(3)](/qb_atomic_pointer_get/3.md), [*qb\_atomic\_int\_exchange\_and\_add*(3)](/qb_atomic_int_exchange_and_add/3.md), [*qb\_atomic\_pointer\_compare\_and\_exchange*(3)](/qb_atomic_pointer_compare_and_exchange/3.md), [*qb\_atomic\_pointer\_set*(3)](/qb_atomic_pointer_set/3.md)

## COPYRIGHT

Copyright (C) 2003 Sebastian Wilhelmi
