CK_PR_FENCE_MEMORY(3)

πŸ’– ck_pr_fence_memory β€” bestie, it's a fence, but for MEMORY πŸ’–

okay so this page is ck_pr_fence_memory(3), and it lives in the Concurrency Kit library β€” that's libck, and you link it with -lck. πŸŽ€

It's giving "enforce partial ordering of all memory operations." Slay.


✨ LIBRARY ✨

Concurrency Kit, aka libck, and you link it with the -lck flag. no cap, that's the whole vibe. πŸ¦‹


🌸 SYNOPSIS 🌸

#include <ck_pr.h>

void
ck_pr_fence_memory();

void
ck_pr_fence_strict_memory();

two little functions, zero arguments, zero drama. πŸ’…


πŸ’« DESCRIPTION πŸ’«

so ck_pr_fence_memory(3) enforces the ordering of any memory operations with respect to the invocation of the function itself. like, everything before it stays before it, everything after it stays after it. periodt. πŸ”₯

this function always serves as an implicit compiler barrier. always. even when nothing else happens, the compiler knows to behave. πŸ‘‘

now the architecture tea β˜•: architectures implementing CK_MD_TSO do not emit a barrier β€” but the compiler barrier semantics still remain, so don't panic. meanwhile, architectures implementing CK_MD_PSO and CK_MD_RMO always emit an instruction that provides the specified ordering guarantees.

and if you want to force the unconditional emission of a memory fence, no matter what the architecture thinks it can get away with? that's what ck_pr_fence_strict_memory() is for. she does not negotiate. πŸ’€βœ¨


🧚 EXAMPLE 🧚

#include <ck_pr.h>

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

void
function(void)
{
        int snapshot_a;

        ck_pr_store_int(&b, 1);
        snapshot_a = ck_pr_load_int(&a);

        /*
         * Make sure previous memory operations are
         * ordered with respect to memory operations
         * following the ck_pr_fence_memory.
         */
        ck_pr_fence_memory();

        ck_pr_store_int(&d, 3);
        ck_pr_store_int(&c, 2);

        return;
}

see how she just chills there in the middle, holding the line between the before and the after? main character energy fr fr. πŸ’œ


πŸ“ RETURN VALUES πŸ“

this function has no return value. nothing to return, nothing to check, just vibes. 🫢


🌈 SEE ALSO 🌈

additional info is available at http://concurrencykit.org/ β€” go look, iykyk. 🌟


okay that's the whole page bestie, you ate this one πŸ’– this was the ck_pr_fence_memory(3) page from April 7, 2013, so like, she's an elder but she still serves ✨ mwah, go write some correct concurrent code, i'm obsessed πŸŽ€

πŸ“¦ where this page comes from