CK_QUEUE(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

okay bestie, sit DOWN 🫢 because today we're talking about ck_queue(3) β€” the Concurrency Kit header that gives you lock-free queues and it's genuinely iconic. No locks. No stress. Just vibes and pointer math. Let's go. πŸ’…


🌸 NAME 🌸

So ck_queue is a whole family of macros β€” and yes, she has a big family, we love a big family. Behold, the full roster:

The CK_LIST_ girlies πŸ’– (multi-reader single-writer singly-linked lists):

  • CK_LIST_EMPTY
  • CK_LIST_ENTRY
  • CK_LIST_FIRST
  • CK_LIST_FOREACH
  • CK_LIST_FOREACH_FROM
  • CK_LIST_FOREACH_SAFE
  • CK_LIST_HEAD
  • CK_LIST_HEAD_INITIALIZER
  • CK_LIST_INIT
  • CK_LIST_INSERT_AFTER
  • CK_LIST_INSERT_BEFORE
  • CK_LIST_INSERT_HEAD
  • CK_LIST_MOVE
  • CK_LIST_NEXT
  • CK_LIST_REMOVE
  • CK_LIST_SWAP

The CK_SLIST_ crew ✨ (singly-linked, and she does not play about the tail):

  • CK_SLIST_EMPTY
  • CK_SLIST_ENTRY
  • CK_SLIST_FIRST
  • CK_SLIST_FOREACH
  • CK_SLIST_FOREACH_FROM
  • CK_SLIST_FOREACH_PREVPTR
  • CK_SLIST_FOREACH_SAFE
  • CK_SLIST_HEAD
  • CK_SLIST_HEAD_INITIALIZER
  • CK_SLIST_INIT
  • CK_SLIST_INSERT_AFTER
  • CK_SLIST_INSERT_HEAD
  • CK_SLIST_MOVE
  • CK_SLIST_NEXT
  • CK_SLIST_REMOVE
  • CK_SLIST_REMOVE_AFTER
  • CK_SLIST_REMOVE_HEAD
  • CK_SLIST_SWAP

The CK_STAILQ_ icons πŸ‘‘ (singly-linked tail queues, the ones who know where the end is):

  • CK_STAILQ_CONCAT
  • CK_STAILQ_EMPTY
  • CK_STAILQ_ENTRY
  • CK_STAILQ_FIRST
  • CK_STAILQ_FOREACH
  • CK_STAILQ_FOREACH_FROM
  • CK_STAILQ_FOREACH_SAFE
  • CK_STAILQ_HEAD
  • CK_STAILQ_HEAD_INITIALIZER
  • CK_STAILQ_INIT
  • CK_STAILQ_INSERT_AFTER
  • CK_STAILQ_INSERT_HEAD
  • CK_STAILQ_INSERT_TAIL
  • CK_STAILQ_MOVE
  • CK_STAILQ_NEXT
  • CK_STAILQ_REMOVE
  • CK_STAILQ_REMOVE_AFTER
  • CK_STAILQ_REMOVE_HEAD
  • CK_STAILQ_SWAP

And what do they all do? multi-reader single-writer singly-linked lists, singly-linked tail queues and lists. That's the whole assignment, and she ate. πŸ“


πŸ“š LIBRARY πŸ“š

This lives in the Concurrency Kit, aka libck, and you link it with -lck. That's the tea. β˜•


✨ SYNOPSIS ✨

First things first, the include. You need this, don't skip it, it's giving necessary:

#include <ck_queue.h>

Then, every single one of the macro calls, exactly as the universe intended:

CK_LIST_EMPTY();

CK_LIST_ENTRY();

CK_LIST_FIRST();

CK_LIST_FOREACH();

CK_LIST_FOREACH_FROM();

CK_LIST_FOREACH_SAFE();

CK_LIST_HEAD();

CK_LIST_HEAD_INITIALIZER();

CK_LIST_INIT();

CK_LIST_INSERT_AFTER();

CK_LIST_INSERT_BEFORE();

CK_LIST_INSERT_HEAD();

CK_LIST_MOVE();

CK_LIST_NEXT();

CK_LIST_REMOVE();

CK_LIST_SWAP();

CK_SLIST_EMPTY();

CK_SLIST_ENTRY();

CK_SLIST_FIRST();

CK_SLIST_FOREACH();

CK_SLIST_FOREACH_FROM();

CK_SLIST_FOREACH_PREVPTR();

CK_SLIST_FOREACH_SAFE();

CK_SLIST_HEAD();

CK_SLIST_HEAD_INITIALIZER();

CK_SLIST_INIT();

CK_SLIST_INSERT_AFTER();

CK_SLIST_INSERT_HEAD();

CK_SLIST_MOVE();

CK_SLIST_NEXT();

CK_SLIST_REMOVE();

CK_SLIST_REMOVE_AFTER();

CK_SLIST_REMOVE_HEAD();

CK_SLIST_SWAP();

CK_STAILQ_CONCAT();

CK_STAILQ_EMPTY();

CK_STAILQ_ENTRY();

CK_STAILQ_FIRST();

CK_STAILQ_FOREACH();

CK_STAILQ_FOREACH_FROM();

CK_STAILQ_FOREACH_SAFE();

CK_STAILQ_HEAD();

CK_STAILQ_HEAD_INITIALIZER();

CK_STAILQ_INIT();

CK_STAILQ_INSERT_AFTER();

CK_STAILQ_INSERT_HEAD();

CK_STAILQ_INSERT_TAIL();

CK_STAILQ_MOVE();

CK_STAILQ_NEXT();

CK_STAILQ_REMOVE();

CK_STAILQ_REMOVE_AFTER();

CK_STAILQ_REMOVE_HEAD();

CK_STAILQ_SWAP();

πŸ’« DESCRIPTION πŸ’«

Okay so if you want more detail than this page gives you, go read your system's manual page for queue β€” that's where the extended lore lives. πŸ“–

Here's the main character moment though: ck_queue is a queue.h-compatible implementation of many-reader-single-writer queues. Which means β€” and I need you to understand how good this is β€” it lets you do safe concurrent iteration, peeking, and read-side access even while there's a single concurrent writer doing her thing, and it does it all with zero locks. No locks. None. Not one. 🧚

And the best part? In many cases, adopting ck_queue is literally just prefixing all your queue operations with CK_. That's it. That's the glow-up. πŸ’…βœ¨


πŸ” SEE ALSO πŸ”

  • queue

Want more? Additional information available at http://concurrencykit.org/ 🌈


That's the page, bestie, you're officially educated. πŸ’–

This was ck_queue(3), dated July 28, 2013. Go forth and be lock-free, you absolute legend. πŸŽ€πŸ¦‹πŸ‘‘

πŸ“¦ where this page comes from