CK_PR_FENCE_STORE(3)

πŸ’… ck_pr_fence_store β€” bestie, we're ordering your stores ✨

okay so this is the manual page for ck_pr_fence_store(3) from the Concurrency Kit β€” yes, that's section 3 of the manual, the "library functions" section, iykyk. grab a snack, we're doing memory ordering πŸ“


πŸ“š LIBRARY

Concurrency Kit β€” that's libck, and when you're linking it you pass -lck. that's the whole vibe. πŸŽ€


✨ SYNOPSIS

like, the receipts:

#include <ck_pr.h>

void
ck_pr_fence_store(void);

void
ck_pr_fence_strict_store(void);

two functions, both returning void, both taking absolutely nothing. no arguments, no drama. πŸ’…


🌸 DESCRIPTION

so ck_pr_fence_store() enforces the ordering of any memory store, of ck_pr_store() calls, and of atomic read-modify-write operations β€” all of that gets ordered relative to the moment you invoke this function. it's giving "everything before this line stays before this line" energy. πŸ‘‘

one thing that's always true no matter what: this function always serves as an implicit compiler barrier. always. no cap.

now, the architecture tea β˜•:

  • on architectures implementing CK_MD_TSO, this operation only serves as a compiler barrier and no fences are emitted at all. it's just vibes and compiler whispering, fr fr.
  • on architectures implementing CK_MD_PSO and CK_MD_RMO, a store fence is emitted. real hardware fence, no pretending.

and if you wanna force that store fence to be emitted unconditionally β€” like, you don't care what the architecture thinks it needs β€” you use ck_pr_fence_strict_store(). she does not ask permission. πŸ’…


🧚 EXAMPLE

here's the whole thing, exactly as written, bestie β€” don't skip it, it's actually cute:

#include <ck_pr.h>

static int a = 0;
static int b = 0;
static int c = 0;

void
function(void)
{

        ck_pr_store_int(&a, 1);

        /*
         * Guarantee that the store to a is completed
         * with respect to the stores of b and c.
         */
        ck_pr_fence_store();
        ck_pr_store_int(&b, 2);
        ck_pr_store_int(&c, 2);

        return;
}

see what's happening? we slam 1 into a, then we hit the fence, and that fence guarantees the store to a is completed with respect to the stores of b and c. then b and c both get their 2s. the fence is the bouncer at the club door, and b and c are not getting in until a is seated. 😀🫢


πŸ¦‹ RETURN VALUES

this function has no return value. nothing. void. it does the thing and dips. πŸ™ˆ

lowkey the most honest function in the whole library

πŸ‘‘ SEE ALSO

the whole friend group, alphabetically-ish, all of them, no one left out:

and there's more lore at http://concurrencykit.org/ if you're obsessed like me. 🌈


k that's the whole page!! this one's dated April 7, 2013 and it lives in section 3 as ck_pr_fence_store(3) β€” go forth and order your stores correctly bestie, ily, mwah πŸ’–πŸŽ€βœ¨

πŸ“¦ where this page comes from