https://github.com/thehxdev/chan
Generic and thread-safe FIFO (Queue) written in C99
https://github.com/thehxdev/chan
Last synced: 10 months ago
JSON representation
Generic and thread-safe FIFO (Queue) written in C99
- Host: GitHub
- URL: https://github.com/thehxdev/chan
- Owner: thehxdev
- Created: 2025-06-10T17:03:03.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-06-10T17:24:42.000Z (12 months ago)
- Last Synced: 2025-06-10T18:47:21.959Z (12 months ago)
- Language: C
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Chan
Chan is a generic, thread-safe, concurrent FIFO (Queue data structure) implementation similar to Go channles in C99.
It supports buffered and unbuffered modes.
> [!NOTE]
> The library itself (`chan.c` and `chan.h`) is implemented with ANSI C99 standard. But some examples use gnu99 standard for non-std functionalities.
> [!WARNING]
> This project is for learning purposes. Do NOT use this in production or your projects.
## Build
This library is written with `pthread` and it's a single `chan.c` file. To build the example program `main.c`:
```bash
make
```
This will build an executable that uses `chan.c` and `chan.h` files. The test creates 4 producer threads that push integer
values to the channel with 4 consumer threads. Consumer threads pop integer values from channel and print them.
## Public interface
Read `chan.h` file. It's easy to understand :)