---
name: "ck_pr_cas"
section: "3"
platform: "linux"
package: "libck-dev"
version: "0.7.2-6"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/ck_pr_cas"
---

# ck\_pr\_cas(3)

atomic compare-and-swap operations

## NAME

**ck\_pr\_cas\_ptr**, **ck\_pr\_cas\_ptr\_value**, **ck\_pr\_cas\_ptr\_2**, **ck\_pr\_cas\_ptr\_2\_value**, **ck\_pr\_cas\_double**, **ck\_pr\_cas\_double\_value**, **ck\_pr\_cas\_char**, **ck\_pr\_cas\_char\_value**, **ck\_pr\_cas\_uint**, **ck\_pr\_cas\_uint\_value**, **ck\_pr\_cas\_int**, **ck\_pr\_cas\_int\_value**, **ck\_pr\_cas\_64\_2**, **ck\_pr\_cas\_64\_2\_value**, **ck\_pr\_cas\_64**, **ck\_pr\_cas\_64\_value**, **ck\_pr\_cas\_32**, **ck\_pr\_cas\_32\_value**, **ck\_pr\_cas\_16**, **ck\_pr\_cas\_16\_value**, **ck\_pr\_cas\_8**, **ck\_pr\_cas\_8\_value** – atomic compare-and-swap operations

## LIBRARY

Concurrency Kit (libck, -lck)

## SYNOPSIS

**#include \<ck\_pr.h\>**

*bool*\

**ck\_pr\_cas\_ptr**(*void \*target*, *void \*old\_value*, *void \*new\_value*);

*bool*\

**ck\_pr\_cas\_ptr\_value**(*void \*target*, *void \*old\_value*, *void \*new\_value*, *void \*original\_value*);

*bool*\

**ck\_pr\_cas\_ptr\_2**(*void \*target*, *void \*old\_value*, *void \*new\_value*);

*bool*\

**ck\_pr\_cas\_ptr\_2\_value**(*void \*target*, *void \*old\_value*, *void \*new\_value*, *void \*original\_value*);

*bool*\

**ck\_pr\_cas\_double**(*double \*target*, *double old\_value*, *double new\_value*);

*bool*\

**ck\_pr\_cas\_double\_value**(*double \*target*, *double old\_value*, *double new\_value*, *double \*original\_value*);

*bool*\

**ck\_pr\_cas\_char**(*char \*target*, *char old\_value*, *char new\_value*);

*bool*\

**ck\_pr\_cas\_char\_value**(*char \*target*, *char old\_value*, *char new\_value*, *char \*original\_value*);

*bool*\

**ck\_pr\_cas\_uint**(*unsigned int \*target*, *unsigned int old\_value*, *unsigned int new\_value*);

*bool*\

**ck\_pr\_cas\_uint\_value**(*unsigned int \*target*, *unsigned int old\_value*, *unsigned int new\_value*, *unsigned int \*original\_value*);

*bool*\

**ck\_pr\_cas\_int**(*int \*target*, *int old\_value*, *int new\_value*);

*bool*\

**ck\_pr\_cas\_int\_value**(*int \*target*, *int old\_value*, *int new\_value*, *int \*original\_value*);

*bool*\

**ck\_pr\_cas\_64\_2**(*uint64\_t target\[static 2\]*, *uint64\_t old\_value\[static 2\]*, *uint64\_t new\_value\[static 2\]*);

*bool*\

**ck\_pr\_cas\_64\_2\_value**(*uint64\_t target\[static 2\]*, *uint64\_t old\_value\[static 2\]*, *uint64\_t new\_value\[static 2\]*, *uint64\_t original\_value\[static 2\]*);

*bool*\

**ck\_pr\_cas\_64**(*uint64\_t \*target*, *uint64\_t old\_value*, *uint64\_t new\_value*);

*bool*\

**ck\_pr\_cas\_64\_value**(*uint64\_t \*target*, *uint64\_t old\_value*, *uint64\_t new\_value*, *uint64\_t \*original\_value*);

*bool*\

**ck\_pr\_cas\_32**(*uint32\_t \*target*, *uint32\_t old\_value*, *uint32\_t new\_value*);

*bool*\

**ck\_pr\_cas\_32\_value**(*uint32\_t \*target*, *uint32\_t old\_value*, *uint32\_t new\_value*, *uint32\_t \*original\_value*);

*bool*\

**ck\_pr\_cas\_16**(*uint16\_t \*target*, *uint16\_t old\_value*, *uint16\_t new\_value*);

*bool*\

**ck\_pr\_cas\_16\_value**(*uint16\_t \*target*, *uint16\_t old\_value*, *uint16\_t new\_value*, *uint16\_t \*original\_value*);

*bool*\

**ck\_pr\_cas\_8**(*uint8\_t \*target*, *uint8\_t old\_value*, *uint8\_t new\_value*);

*bool*\

**ck\_pr\_cas\_8\_value**(*uint8\_t \*target*, *uint8\_t old\_value*, *uint8\_t new\_value*, *uint8\_t \*original\_value*);

## DESCRIPTION

The **ck\_pr\_cas**(*3*) family of functions atomically compare the value in *target* for equality with *old\_value* and if so, replace the value pointed to by *target* with the value specified by *new\_value*. If the value in *target* was not equal to the value specified by *old\_value* then no modifications occur to the value in *target*. The \*\_value form of these functions unconditionally update *original\_value*.

## RETURN VALUES

This family of functions return true if the value in *target* was modified as a result of the operation. Otherwise, they return false.

## SEE ALSO

[ck\_pr\_fence\_load(3)](/ck_pr_fence_load/3.md), [ck\_pr\_fence\_load\_depends(3)](/ck_pr_fence_load_depends/3.md), [ck\_pr\_fence\_store(3)](/ck_pr_fence_store/3.md), [ck\_pr\_fence\_memory(3)](/ck_pr_fence_memory/3.md), [ck\_pr\_load(3)](/ck_pr_load/3.md), [ck\_pr\_store(3)](/ck_pr_store/3.md), [ck\_pr\_fas(3)](/ck_pr_fas/3.md), [ck\_pr\_faa(3)](/ck_pr_faa/3.md), [ck\_pr\_inc(3)](/ck_pr_inc/3.md), [ck\_pr\_dec(3)](/ck_pr_dec/3.md), [ck\_pr\_neg(3)](/ck_pr_neg/3.md), [ck\_pr\_not(3)](/ck_pr_not/3.md), [ck\_pr\_sub(3)](/ck_pr_sub/3.md), [ck\_pr\_and(3)](/ck_pr_and/3.md), [ck\_pr\_or(3)](/ck_pr_or/3.md), [ck\_pr\_xor(3)](/ck_pr_xor/3.md), [ck\_pr\_add(3)](/ck_pr_add/3.md), [ck\_pr\_btc(3)](/ck_pr_btc/3.md), [ck\_pr\_bts(3)](/ck_pr_bts/3.md), [ck\_pr\_btr(3)](/ck_pr_btr/3.md)

Additional information available at http://concurrencykit.org/
