An open API service indexing awesome lists of open source software.

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

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 :)