- C 94.7%
- Makefile 5.3%
1414 Portable C Concurrency Library
dfthread implements basic and portable threading and syncrhonization primitives.
The interface mimics standard C11 threading.
dfthread works on Windows and any platform supporting POSIX threads.
It requires a GNU C compatible compiler to build.
Why?
Because standard C11 threading is seldom implemented, and considered optional by the standard itself.
So I felt the necessity of a reliable, lightweight, basic threading library that would give me the most basic primitives to write portable concurrent code.
dfthread also has a few important differences compared to standard C11 threading:
- Thread creation allows to specify stack size hint and CPU affinity.
- Mutexes and condition variables can be initialized statically.
- There is no support for recursive mutexes.
- There is no support to detach a thread.
- Threads can't return a value upon exit.
Design choices
-
Only supports GNU C compatible compilers (e.g. GCC, clang, Intel C Compiler), since
dfthreaduses GNU C extensions to provide additional safety and scoped resource acquisition and release. -
Do not aim to be compatible with C++.
-
Only support static linking, in order to be as lightweight as possible, and allow stripping unnecessary functionality from the final executable.
-
Make extensive use of
inlinefunctions, to keep the performance as close as possible to using platform primitives directly.
Building
dfthread uses Makefile to manage its build .
You can build dfthread using make, running the following command:
$ make
Or, equivalently:
$ make all
You can customize the compilation flags using the CFLAGS variable, for example:
$ make CFLAGS="-Os"
Other familiar variables, such as CC, AR, ARFLAGS and RANLIB are also supported.
To remove any file generated by a previous build, run:
$ make clean
You can use dfthread in your project by linking to the generated dfthread library plus
any platform specific threading library, such as pthreads on POSIX,
and including the dfthread.h and dfthreaddef.h headers as needed.
License
MIT, see LICENSE file for details.