CK_EPOCH_SYNCHRONIZE(3)

πŸ“¦
version 0.7.2 Β· 2 versions
, in alpine 3.24, debian trixie, epel 10, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– CK_EPOCH_SYNCHRONIZE(3) πŸ’–

okay bestie, so this one lives in the Concurrency Kit library, aka libck, and you link it with -lck. It's a section 3 manpage, and it's literally the "wait for a grace period" girlie. Let's get into it πŸ¦‹


✨ NAME ✨

ck_epoch_synchronize β€” block until a grace period has been detected 🫢


πŸ“š LIBRARY πŸ“š

Concurrency Kit (that's libck, and you pass -lck) πŸ’…


🌸 SYNOPSIS 🌸

#include <ck_epoch.h>

void
ck_epoch_synchronize(ck_epoch_record_t *record);

πŸ’« DESCRIPTION πŸ’«

So ck_epoch_synchronize(3) will block the caller until a grace period has been detected, following the whole semantics of epoch reclamation. No cap. It just sits there, patiently, until the coast is clear. ⏳

🚨 Important bestie: it is NOT safe to call this function on a record that is in an active section. Like, do not do that. That's a vibe check you will fail. 😭

Any objects that need safe memory reclamation and are logically deleted are safe for physical deletion right after you call ck_epoch_synchronize(3). Slay. ✨

But listen β€” if you need all callbacks to be dispatched, the move is to use ck_epoch_barrier(3) instead, OR you follow up your ck_epoch_synchronize(3) call with ck_epoch_reclaim(3). Either way, get those callbacks their moment. πŸ’…


πŸŽ€ EXAMPLE πŸŽ€

okay here's the whole thing, and it's giving main character energy fr fr:

#include <ck_epoch.h>
#include <ck_stack.h>
#include <stdlib.h>

/*
 * epoch was previously initialized with ck_epoch_init.
 * stack was previously initialized with ck_stack_init.
 */
ck_epoch_t *epoch;
ck_stack_t *stack;

void
function(void)
{
        ck_epoch_record_t *record;
        ck_stack_entry_t *s;

        record = malloc(sizeof *record);
        ck_epoch_register(&epoch, record, NULL);

        /*
         * We are using an epoch section here to guarantee no
         * nodes in the stack are deleted while we are dereferencing
         * them. This is needed here because there are multiple writers.
         * If there was only one thread popping from the this stack,
         * then there is no need to ck_epoch_begin/ck_epoch_end.
         */
        ck_epoch_begin(record);

        /* Logically delete an object. */
        s = ck_stack_pop_upmc(stack);

        ck_epoch_end(record);

        /*
         * Wait until no threads could possibly have a reference to the
         * object we just popped (assume all threads are simply executing
         * ck_stack_pop_upmc).
         */
        ck_epoch_synchronize(record);

        /* It is now safe to physically delete the object. */
        free(s);
        return;
}

see how we ck_epoch_begin(record) before popping so nobody deletes nodes while we're dereferencing them? that's the whole point, and it matters because there are multiple writers. if only one thread was popping off this stack, you wouldn't even need ck_epoch_begin/ck_epoch_end. iykyk 🌈


πŸ”₯ RETURN VALUES πŸ”₯

This function has no return value. Nothing. Nada. It just vibes and blocks. πŸ’€


πŸ™ˆ ERRORS πŸ™ˆ

The object pointed to by record must have been previously registered via ck_epoch_register(3). That's the whole deal β€” if it wasn't registered, that's on you bestie. 🫠


πŸ‘‘ SEE ALSO πŸ‘‘

Additional information available at http://concurrencykit.org/ β€” go be nosy, it's worth it πŸ¦‹


okay that's the whole page bestie!! this one was dated September 2, 2012, and it's part of the CK_EPOCH_SYNCHRONIZE(3) manpage from Concurrency Kit. go forth, synchronize your grace periods, and stay safe out there πŸ’–βœ¨πŸŽ€ periodt.

πŸ“¦ where this page comes from