CK_RING_DEQUEUE_SPMC(3)
π NAME π
ck_ring_dequeue_spmc β dequeue pointer from bounded FIFO πΈ
okay so bestie, this is the Concurrency Kit manual, section 3, and we're talking about ck_ring_dequeue_spmc(3) specifically. she's a single-consumer girlie pulling pointers out of a bounded FIFO. let's get into it π
π LIBRARY π
Concurrency Kit (libck, -lck) π«Ά
β¨ SYNOPSIS β¨
#include <ck_ring.h>
bool
ck_ring_dequeue_spmc(ck_ring_t *ring, ck_ring_buffer_t *buffer,
void *result);
π¦ DESCRIPTION π¦
so like, ck_ring_dequeue_spmc(3) dequeues a pointer from the bounded buffer pointed to by ring, and she does it FIFO fashion β first in, first out, no cutting the line bestie π
. That pointer gets stored in the pointer pointed to by result. easy!
now here's the thing: the buffer pointed to by buffer must be unique to ring. like, not shared, not communal, hers and hers only π. the whole reason the ring and the buffer are decoupled like this is to address use-cases involving multiple address spaces and DMA, among others β it's giving "separation for the plot" β¨.
if you're on non-POSIX platforms, or you just want strict compliance with C, then it's recommended that you pass a pointer of type void ** for result. noted π
and the actual concurrency tea: this function is safe to call without locking for up to UINT_MAX concurrent invocations of ck_ring_dequeue_spmc(3) or ck_ring_trydequeue_spmc(3), and up to one concurrent ck_ring_enqueue_spmc(3) or ck_ring_tryenqueue_spmc(3) invocation. one. single. producer. the way she has lock-free progress guarantees? iconic, no notes π
bestie pls respect the one-producer limit, it's not a suggestion, it's the whole vibe of the algorithm π
π 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 it is empty. */
while (ck_ring_dequeue_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;
}
see how she just keeps looping until the ring says "ma'am, I'm empty"? π₯Ή the oldest pointer comes out first every time. that's the FIFO fantasy fr fr.
π RETURN VALUES π
- the function returns
trueif the buffer was non-empty π - the result of the dequeue operation is stored in the value pointed to by
result⨠- the function returns
falseif the buffer was empty β and heads up, when that happens the value inresultis undefined π so don't go reading it, that's a trap bestie
π SEE ALSO π
ck_ring_init(3)ck_ring_trydequeue_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 info available at http://concurrencykit.org/ π
and that's the whole page bestie π«Ά this diva was written back on April 20, 2013 and lives in the CK_RING_DEQUEUE_SPMC(3) era of the Concurrency Kit manual. go forth and dequeue responsibly π
β¨π
π¦ 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