- C 93.6%
- CMake 3.6%
- C++ 2.2%
- Nushell 0.6%
| .forgejo/workflows | Initial commit | |
| docs | Initial commit | |
| include | Initial commit | |
| src | Initial commit | |
| tests | Initial commit | |
| .clangd | Initial commit | |
| .gitignore | Initial commit | |
| CMakeLists.txt | Initial commit | |
| LICENSE.md | Initial commit | |
| README.md | Initial commit | |
| todo.txt | Initial commit | |
📨 chic
Buffered channels, such as the Go programming language's chan or Plan 9's Channel, written in C17.
These channels are suitable for inter-process communication in realtime applications as they do not use mutex, semaphore, or anything else that blocks or requires a context switch. They synchronize using atomic operations only. They are intended to have better/bounded worst-case performance, even at the expense of average-case performance.
These channels support sending and receiving batches of items, and also provide methods to safely read and write directly to their underlying ringbuffer for zero-copy communication.
Chic provides four flavors of channels:
- Multiple-producer, multiple-consumer: If you're not sure what you need, use this one. This is most similar to Go's
chan. - Multiple-producer, single-consumer: Receiving from the channel is optimized under the assumption that only one thread receives from the channel.
- Single-producer, multiple-consumer: Sending to the channel is optimized under the assumption that only one thread sends to the channel.
- Single-producer, single-consumer: All channel operations are optimized under the assumption that only one thread sends to the channel and only one thread receives from the channel.
Usage
Chic is a work-in-progress and requires further testing and refinement before usage is advisable. That said, basic examples can be found in tests/*p*c_demo.c.
Building
Chic depends on the CMake build system and the presence of a compiler that supports both C17 and <stdatomic.h>. The optional tests require support for <threads.h>.
Build Chic as a static library (preferred):
cmake -B build && cmake --build build
Build Chic as a dynamic library:
cmake -DBUILD_SHARED_LIBS=ON -B build && cmake --build build
Documentation
Documentation is available at rubiefawn.codeberg.page/chic.
HTML documentation can be built locally if you have Doxygen installed by running:
cmake -B build && cmake --build build --target docs
License
Chic is available under the terms of the Mozilla Public License, v. 2.0.
The intent is to allow anybody to freely use and link Chic to any other software under any other license, as long as Chic itself remains unmodified. If you modify Chic, those derivative works must be released under the MPL-2.0. In other words, use Chic freely for any purpose, but in turn, please freely share any changes you make to it.
Resources
📮 Blog Posts
- Andrea Lattuada — The design and implementation of a lock-free ring-buffer with contiguous reservations
- Erik Rigtorp — Optimizing a ring buffer for throughput
- Timur Doumler — Using locks in real-time audio processing, safely
- Alexander Krizhanovsky — Lock-free Multi-producer Multi-consumer Queue on Ring Buffer
- Dmitry Vyukov — Bounded MPMC Queue
- Cameron Desrochers — Detailed Design of a Lock-Free Queue
- Ross Bencina — Real-time audio programming 101: time waits for nothing
- David Álvarez Rosa — Optimizing a Lock-Free Ring Buffer
📺 Videos
- Dave Rowland & Fabian Renn-Giles — Real-time 101 - Part II: The real-time audio developer’s toolbox
- Charles Frasch — Single Producer Single Consumer Lock-free FIFO From the Ground Up
- Matt Kulukundis — Building a Lock-free Multi-producer, Multi-consumer Queue for Tcmalloc
📃 Papers
- Patrick P. C. Lee, Tian Bu and Girish Chandranmenon — A lock-free, cache-efficient multi-core synchronization mechanism for line-rate network traffic monitoring (pdf)
- Martin Thompson, Dave Farley, Michael Barker, Patricia Gee, Andrew Stewart — LMAX Disruptor: High performance alternative to bounded queues for exchanging data between concurrent threads
- Yucheng Fang, Huibiao Zhu, Frank Zeyda and Yuan Fei — Modeling and analysis of the disruptor framework in CSP
🔖 Miscellaneous
- 9front — Plan 9's
Channelas described inman 2 thread - go.dev — Channels