CK_TFLOCK(3)
π ck_tflock(3) β centralized task-fair reader-writer locks π
okay bestie, sit down, hydrate, and let me tell you about ck_tflock β that's the page you're on, ck_tflock(3), the centralized task-fair reader-writer lock from Concurrency Kit. it's giving locks but make it fair. let's go π
β¨ NAME β¨
ck_tflock_ticket_init, ck_tflock_ticket_write_lock, ck_tflock_ticket_write_unlock, ck_tflock_ticket_read_lock, ck_tflock_ticket_read_unlock β centralized task-fair reader-writer locks
like, that's the whole squad. five functions, one lock, zero drama π«Ά
π LIBRARY π
Concurrency Kit (libck, -lck)
so when you link, you link against libck with -lck. that's the whole vibe. π
πΈ SYNOPSIS πΈ
#include <ck_tflock.h>
ck_tflock_ticket_t lock = CK_TFLOCK_TICKET_INITIALIZER;
void
ck_tflock_ticket_init(ck_tflock_ticket_t *lock);
void
ck_tflock_ticket_write_lock(ck_tflock_ticket_t *lock);
void
ck_tflock_ticket_write_unlock(ck_tflock_ticket_t *lock);
void
ck_tflock_ticket_read_lock(ck_tflock_ticket_t *lock);
void
ck_tflock_ticket_read_unlock(ck_tflock_ticket_t *lock);
okay so the glow-up here: you got your type ck_tflock_ticket_t, you got a static initializer CK_TFLOCK_TICKET_INITIALIZER so your lock is ready before main even wakes up, and you got five functions β one init, and a lock/unlock pair for readers plus a lock/unlock pair for writers. every single one returns void and takes exactly one ck_tflock_ticket_t *lock. no extra args, no surprises. β¨
π¦ DESCRIPTION π¦
so what is this thing? it's a centralized task-fair reader-writer lock. periodt.
what that means in bestie terms: readers and writers both get their turn, and the fairness is the whole point β nobody's getting starved while somebody else hogs the lock forever. that's the "task-fair" part and it's lowkey the main character of this entire manpage. π
and the tea? it requires little space overhead and it has a low latency fast path. so it's small and it's quick when things are chill. it's giving efficient. it's giving iconic. π
π₯ EXAMPLE π₯
here's the whole thing in action, copy it exactly as it's written, bestie:
#include <ck_tflock.h>
static ck_tflock_ticket_t lock = CK_TFLOCK_INITIALIZER;
static void
reader(void)
{
for (;;) {
ck_tflock_ticket_read_lock(&lock);
/* Read-side critical section. */
ck_tflock_ticket_read_unlock(&lock);
}
return;
}
static void
writer(void)
{
for (;;) {
ck_tflock_ticket_write_lock(&lock);
/* Write-side critical section. */
ck_tflock_ticket_write_unlock(&lock);
}
return;
}
see how the reader grabs ck_tflock_ticket_read_lock(&lock), does its little read-side critical section, then ck_tflock_ticket_read_unlock(&lock)? and the writer does the exact same dance but with ck_tflock_ticket_write_lock(&lock) and ck_tflock_ticket_write_unlock(&lock). both of them loop forever with for (;;) and both return; at the end. that's the pattern. that's it. you ate. π
little note bestie: the initializer in this example is spelledCK_TFLOCK_INITIALIZER, and in the SYNOPSIS it'sCK_TFLOCK_TICKET_INITIALIZER. write each one exactly the way it appears in the block you're copying from. do not freestyle the spelling, i am begging π
π SEE ALSO π
and if you want even more, the additional information lives at http://concurrencykit.org/ π
and that's the page!! April 22, 2014. β that's when this beauty got dated, from the ck_tflock(3) manual page itself. mwah. go forth and lock responsibly, bestie π«Άπβ¨
π¦ 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 2014 Samy Al Bahra
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms