CK_PR_FENCE_ATOMIC(3)

πŸ’– CK_PR_FENCE_ATOMIC(3) πŸ’–

okay bestie, pull up a chair, because we're talking about ck_pr_fence_atomic β€” it's a page from the Concurrency Kit manual (that's section 3, the library one, iykyk) ✨


🌈 LIBRARY

Concurrency Kit β€” link it like libck, so -lck πŸŽ€


✨ SYNOPSIS ✨

#include <ck_pr.h>

void
ck_pr_fence_atomic(void);

void
ck_pr_fence_strict_atomic(void);

πŸ¦‹ DESCRIPTION πŸ¦‹

so. ck_pr_fence_atomic() is the girl who keeps the timeline straight πŸ’… She enforces the ordering of any atomic read-modify-write operations relative to whenever you invoke her. Like, if you call her, she makes sure everything lines up in the right order around that call. periodt.

This function always serves as an implicit compiler barrier. Always. No cap. 🫢

Now here's where the architecture lore kicks in:

  • On architectures implementing CK_MD_TSO, this operation only serves as a compiler barrier β€” and like, no fences are emitted at all. she's just vibing. 😌
  • On architectures implementing CK_MD_PSO and CK_MD_RMO, a store fence is emitted. okay so she does put in work there. πŸ”₯

But if you want to force the unconditional emission of a fence β€” no matter what, no excuses, no architecture opinions β€” use ck_pr_fence_strict_atomic(). she does not skip leg day. πŸ‘‘

lowkey important: the strict version is the one you reach for when you need that fence emitted, period, instead of "well, depends on the memory model bestie." πŸ™ˆ

🌸 EXAMPLE 🌸

here's the whole vibe, verbatim, don't @ me:

#include <ck_pr.h>

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

void
function(void)
{

        ck_pr_fas_int(&a, 1);

        /*
         * Guarantee that the update to a is completed
         * with respect to the updates of b and c.
         */
        ck_pr_fence_atomic();
        ck_pr_fas_int(&b, 2);
        ck_pr_fas_int(&c, 2);

        return;
}

like… the ck_pr_fence_atomic() in the middle is literally the main character here πŸ’œ she's guaranteeing that the update to a is completed with respect to the updates of b and c. iconic behavior, honestly.


πŸŽ€ RETURN VALUES πŸŽ€

This function has no return value. she gives nothing back and that's the point. πŸ’€ (not in a bad way!! in a "void function" way 🫢)


πŸ‘‘ SEE ALSO πŸ‘‘

the whole friend group, go say hi:

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


and that's the whole page, bestie!! this one was dated May 16, 2013, from the Concurrency Kit crew β€” mwah, thank you for the fences, we're obsessed πŸ’–βœ¨πŸ§šβ€β™€οΈ

πŸ“¦ where this page comes from