CK_PR_FAA(3)

✨ ck_pr_faa β€” atomic fetch-and-add operations ✨

okay bestie, gather round, because this is genuinely one of the most iconic little families in all of libck and I need you to be seated for it πŸ’…


πŸ“š LIBRARY

Concurrency Kit (libck, -lck)

like, that's the whole vibe. you link against -lck and you're in. no cap.


πŸŽ€ SYNOPSIS

#include <ck_pr.h>

uintptr_t
ck_pr_faa_ptr(void *target, uintptr_t delta);

double
ck_pr_faa_double(double *target, double delta);

char
ck_pr_faa_char(char *target, char delta);

unsigned int
ck_pr_faa_uint(unsigned int *target, unsigned int delta);

int
ck_pr_faa_int(int *target, int delta);

uint64_t
ck_pr_faa_64(uint64_t *target, uint64_t delta);

uint32_t
ck_pr_faa_32(uint32_t *target, uint32_t delta);

uint16_t
ck_pr_faa_16(uint16_t *target, uint16_t delta);

uint8_t
ck_pr_faa_8(uint8_t *target, uint8_t delta);

nine functions. nine little main characters. each one for a different type. it's giving "we have options and we are not sorry" 🌈


πŸ¦‹ DESCRIPTION

so the ck_pr_faa(3) family of functions atomically fetches the value pointed to by target and adds the value specified by delta to the value pointed to by target.

that's it. that's the whole thing. atomic fetch-and-add. the fetch and the add are one indivisible moment β€” nobody can sneak in between them, no other thread gets to peek at some awkward in-between state, it just happens. it's giving ✨seamless✨.

iykyk πŸ’œ


🌸 RETURN VALUES

this function returns the value pointed to by target at the time of operation invocation β€” before the addition operation is applied.

so like. heads up bestie. you get the old value back. the value from before. the add already happened by the time you're holding your return value, but what you're holding is the past. it's giving time traveler πŸ•°οΈβœ¨


πŸ”₯ SEE ALSO

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


okay so real talk, go read the whole little family. they all hang out together and they're all obsessed with each other. the fences, the loads, the stores, the bit twiddlers β€” it's a whole friend group and you're invited 🫢

that's the page bestie!! πŸŽ€ this was ck_pr_faa(3), brought to you by the April 7, 2013 girlies, and yes that date is iconic, and yes it's still serving. periodt πŸ’–βœ¨πŸ¦‹πŸŒΈπŸ‘‘

πŸ“¦ where this page comes from