CK_PR_FENCE_STORE_LOAD(3)

πŸ’– CK_PR_FENCE_STORE_LOAD(3) πŸ’–

okay bestie, gather round, we're talking about ck_pr_fence_store_load β€” a lil function from the CK_PR_FENCE_STORE_LOAD(3) manual page that makes your stores and your loads stop fighting over who goes first. it's giving traffic cop energy fr fr 🚦✨


πŸŽ€ NAME πŸŽ€

ck_pr_fence_store_load β€” enforce ordering of store operations to load operations. that's it, that's the whole job, and she does it flawlessly πŸ’…


πŸ“š LIBRARY πŸ“š

Concurrency Kit</purl> β€” link it with libck, so like -lck. yes that's the flag, write it down πŸ“


✨ SYNOPSIS ✨

#include <ck_pr.h>

void
ck_pr_fence_store_load(void);

void
ck_pr_fence_strict_store_load(void);

two functions, same vibe, both just sitting there with no arguments. iconic honestly πŸ‘‘


πŸ’« DESCRIPTION πŸ’«

okay so here's the tea, bestie 🍡. The ck_pr_fence_store_load() function enforces the ordering of any memory store, ck_pr_store() and atomic read-modify-write operations to load operations relative to the invocation of the function. translation: everything that writes has to be done being all write-y before the stuff that reads gets to go. no cutting the line. no cap 🚫

this function always serves as an implicit compiler barrier. so the compiler is not gonna get cute and reorder things behind your back, periodt.

and listen β€” a fence will currently always be emitted for this operation, including for TSO memory model targets. so like, even on the architectures where you might be like "surely this is a no-op", nope, fence is getting emitted. every time. she shows up to work 🌸


🌈 EXAMPLE 🌈

#include <ck_pr.h>

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

void
function(void)
{
        unsigned int snapshot_b;

        ck_pr_store_int(&a, 1);

        /*
         * Guarantee that the store to a is completed
         * with respect to load from b.
         */
        ck_pr_fence_store_load();
        snapshot_b = ck_pr_load_int(&b, 2);
        return;
}

see how the fence is chilling between the store and the load? that's the whole point 🫢 the store to a is guaranteed to be completed with respect to the load from b. the comment says it, the code does it, we love a self-aware snippet πŸ’œ


πŸ”₯ RETURN VALUES πŸ”₯

This function has no return value. she gives you nothing back and honestly? that's fine, her job was the ordering πŸ’€


πŸ‘€ SEE ALSO πŸ‘€

Additional information available at http://concurrencykit.org/ β€” go peek, it's a whole website, very demure 🌐


okay that's the page!! this was the CK_PR_FENCE_STORE_LOAD(3) man page, dated May 18, 2013, and this particular glow-up was served to you by the source CK_PR_FENCE_STORE_LOAD(3) (yes she contains herself, it's very meta, we don't question it) πŸ’– mwah, go write some correctly-ordered memory ops, bestie, i believe in you 🧚✨

πŸ“¦ where this page comes from