CK_RING_TRYDEQUEUE_SPMC(3)
๐ CK_RING_TRYDEQUEUE_SPMC ๐
okay bestie, welcome to ck_ring_trydequeue_spmc(3) โ yes that's the whole manual name, say it three times fast, i dare you ๐ซถ it lives in the Concurrency Kit corner of the universe, aka libck, link it with -lck.
โจ NAME โจ
ck_ring_trydequeue_spmc โ dequeue from a bounded FIFO, and it's allowed to just. fail. spuriously. no drama, that's the whole bit ๐
๐ LIBRARY ๐
Concurrency Kit (libck, -lck) โ iconic, legendary, lowkey the moment.
๐ SYNOPSIS ๐
#include <ck_ring.h>
bool
ck_ring_trydequeue_spmc(ck_ring_t *ring, ck_ring_buffer_t *buffer,
void *result);
๐ฆ DESCRIPTION ๐ฆ
so. ck_ring_trydequeue_spmc(3) tries to dequeue one pointer from the bounded buffer that ring points at, and it does it FIFO style โ first in, first out, oldest pointer first, no cutting the line ๐
โโ๏ธ that pointer lands in the pointer that result points at.
the buffer that buffer points at has to be unique to ring โ no sharing, not even a little โ and it must point to an array of ck_ring_buffer_t that's long enough (long enough meaning: according to the power-of-2 elements in the buffer, so do the math, bestie ๐งฎโจ).
why is the ring decoupled from the buffer at all?? because use-cases like multiple address spaces and DMA (among others!!) needed it, and honestly? she ate. ๐
if you're on non-POSIX platforms or you simply want strict compliance with C, then the recommendation is to pass a pointer of type void ** for result. noted, respected, do it.
concurrency tea time โ: this function is safe to call without locking for UINT_MAX concurrent ck_ring_dequeue_spmc(3) or ck_ring_trydequeue_spmc(3) invocations, plus up to one concurrent ck_ring_enqueue_spmc(3) or ck_ring_tryenqueue_spmc(3) invocation. that's it, that's the budget. one enqueuer, bestie, don't get greedy ๐ซถ
this operation will always complete in a bounded number of steps. no infinite spirals, no waiting forever, we respect your time.
and now the part that makes people scream: it is possible for the function to return false even if ring is non-empty. yes. literally that. spurious failure is not a bug, it's a lifestyle. ๐ญ
also the original manpage just ends that paragraph with the word "This" and nothing else ๐ not me getting left on read by a documentation file. we keep it, we honor it, we move on.
๐ธ EXAMPLE ๐ธ
#include <ck_ring.h>
/* This ring was previously initialized with ck_ring_init. */
ck_ring_t ring;
/* The ring was initialized for 1023 elements. */
ck_ring_buffer_t buffer[1024];
void
dequeue(void)
{
void *result;
/* Dequeue from ring until contention is actively observed. */
while (ck_ring_trydequeue_spmc(&ring, &buffer, &result) == true) {
/*
* Results contains the oldest pointer in ring
* since the dequeue operation returned true.
*/
operation(result);
}
/* An empty ring was encountered, leave. */
return;
}
look at that loop go ๐ฅ keep dequeuing until you actually observe contention, and the second it returns false, you leave. main character exit. ๐ชโจ
๐ RETURN VALUES ๐
- the function returns
trueif the dequeue operation completely successfully goes through in a bounded number of steps โ and the result of the dequeue is stored in the value thatresultpoints to. slay. ๐ - otherwise the function returns
falseif the buffer was empty, or if the operation could not be completed in a bounded number of steps.
โ ๏ธ if the function returnsfalse, then the contents ofresultare undefined. do not read it. do not peek. do not look at it and hope. undefined is undefined, bestie, respect the boundary ๐
๐ซถ SEE ALSO ๐ซถ
ck_ring_init(3)ck_ring_dequeue_spmc(3)ck_ring_enqueue_spmc(3)ck_ring_enqueue_spmc_size(3)ck_ring_dequeue_spsc(3)ck_ring_enqueue_spsc(3)ck_ring_enqueue_spsc_size(3)ck_ring_capacity(3)ck_ring_size(3)
additional information available at http://concurrencykit.org/ โ go, read, obsess ๐ฆ
and that's the whole page, babes ๐ this was CK_RING_TRYDEQUEUE_SPMC(3), dated April 20, 2013, and it's giving timeless. no cap. periodt. ๐โญ๐
๐ฆ where this page comes from
- alpine 3.24: ck-doc 0.7.2-r1 ยท BSD-2-Clause AND Apache-2.0
- debian bookworm: libck-dev 0.7.1-10 ยท BSD-2-Clause
- debian trixie: libck-dev 0.7.2-6 ยท BSD-2-Clause
- epel 10: ck-devel 0.7.2-1.el10_1 ยท BSD-2-clause AND Apache-2.0 AND BSD-3-clause
- epel 9: ck-devel 0.7.0-10.el9 ยท BSD
- fedora 43: ck-devel 0.7.2-2.fc43 ยท BSD-2-clause AND Apache-2.0 AND BSD-3-clause
- fedora 43: ck-devel 0.7.2-2.fc43 ยท BSD-2-clause AND Apache-2.0 AND BSD-3-clause
- fedora 44: ck-devel 0.7.2-4.fc44 ยท BSD-2-clause AND Apache-2.0 AND BSD-3-clause
- fedora 44: ck-devel 0.7.2-4.fc44 ยท BSD-2-clause AND Apache-2.0 AND BSD-3-clause
- nixos 26.05: ck 0.7.2
- nixpkgs unstable: ck 0.7.2
- opensuse-leap 16.0: ck-devel 0.7.2-bp160.1.9 ยท Apache-2.0 AND BSD-2-Clause
- opensuse-leap 16.0: ck-devel 0.7.2-bp160.1.9 ยท Apache-2.0 AND BSD-2-Clause
- opensuse-leap 16.0: ck-devel 0.7.2-bp160.1.9 ยท Apache-2.0 AND BSD-2-Clause
- ubuntu jammy: libck-dev 0.7.1-6ubuntu2 ยท BSD-2-Clause
- ubuntu noble: libck-dev 0.7.1-13build1 ยท BSD-2-Clause
- ubuntu questing: libck-dev 0.7.2-5ubuntu1
- ubuntu resolute: libck-dev 0.7.2-5ubuntu2 ยท BSD-2-Clause
- ubuntu stonking: libck-dev 0.7.2-11 ยท BSD-2-Clause
- Copyright 2012-2013 Samy Al Bahra
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms