CK_PR_FENCE_LOAD_STORE(3)

✨ ck_pr_fence_load_store β€” bestie's guide to making loads wait their turn before stores πŸ’…

okay so this is the manual for ck_pr_fence_load_store(3) and honestly? she's a baddie. let's get into it 🫢


πŸ“š LIBRARY

Concurrency Kit β€” aka libck, and you link her with -lck. that's it that's the vibe. πŸ”₯


🌸 SYNOPSIS

#include <ck_pr.h>

void
ck_pr_fence_load_store(void);

void
ck_pr_fence_strict_load_store(void);

two whole functions. twins. sisters. one is chill, one is strict. pick your fighter πŸ’–


✨ DESCRIPTION

so what does this fence actually do, bestie? it enforces the ordering of any memory load and ck_pr_load(3) operations with respect to store operations, relative to the moment you invoke the function. it's giving "no you don't get to reorder me, i'm the main character" πŸ‘‘

and there's more: any store operations that were committed on remote processors and received by the calling processor before the invocation of ck_pr_fence_load_store() are also made visible only after a call to the ck_pr_fence_load family of functions. so like, the visibility timing is not a free-for-all, it's scheduled, periodt.

this function always serves as an implicit compiler barrier β€” always, no exceptions, she's reliable like that.

now the architecture tea β˜•: on architectures with CK_MD_TSO or CK_MD_PSO specified (that's total store ordering and partial store ordering respectively, iykyk), this operation only serves as a compiler barrier and no fence instructions will be emitted. so like, no hardware fence, just the compiler behaving.

but if you want to force the unconditional emission of a load fence? use ck_pr_fence_strict_load_store(). that's the strict twin's whole job. she doesn't do vibes, she does instructions. πŸ’€

and architectures implementing CK_MD_RMO? they always emit a fence. no discussion, no debate. 🌈


πŸŽ€ EXAMPLE

okay bestie here's what it looks like in the wild:

#include <ck_pr.h>

static unsigned int a;
static unsigned int b;

void
function(void)
{
        unsigned int snapshot_a;

        snapshot_a = ck_pr_load_uint(&a);

        /*
         * Guarantee that the load from "a" completes
         * before the store to "b".
         */
        ck_pr_fence_load_store();
        ck_pr_store_uint(&b, 1);

        return;
}

see how she loads a, drops the fence, then stores b? that's the whole point. the comment literally spells it out: guarantee that the load from "a" completes before the store to "b". iconic behavior, no notes πŸ’–


πŸ¦‹ RETURN VALUES

this function has no return value. she gives you nothing back. she just does her job and leaves. queen shit. πŸ™ˆ


🌟 SEE ALSO

the whole friend group, go say hi to all of them:

and if you want even more, additional information is available at http://concurrencykit.org/ 🌈✨


lowkey sign-off: this page is dated May 18, 2013 and it lives in the CK_PR_FENCE_LOAD_STORE(3) section of your friendly neighborhood manual. go forth and fence responsibly, bestie πŸ’œπŸŒΈ
πŸ“¦ where this page comes from