A small library providing generic interface for multithreading across different platforms.
Created due to the fact that macOS does not support <threads.h> in C11.
See the documentation.
- Mutex (Mutual exclusion)
- Cond (Condition variable)
- Thread (sleep, yield, etc.)
- Thread pool (tasks)
- Atomics (fetch add)
- Supports Windows, macOS and Linux
voidmutexExample()
{
Mutexmutex=createMutex();
if (!mutex)
abort();
lockMutex(mutex);
// Do some synchronized work...unlockMutex(mutex);
destroyMutex(mutex);
}
// ========================================staticvoidonUpdate(void*argument)
{
volatilebool*isRunning=argument;
while (*isRunning)
{
// Do some parallel work...sleepThread(0.001);
}
}
voidthreadExample()
{
volatileboolisRunning= true;
Threadthread=createThread(
onUpdate, &isRunning);
if (!thread)
abort();
isRunning= false;
joinThread(thread);
destroyThread(thread);
}- C99 compiler
- C++17 compiler (optional)
- Git 2.53+
- CMake 3.10+
Use building instructions to install all required tools and libraries.
| Name | Description | Default value |
|---|---|---|
| MPMT_BUILD_SHARED | Build MPMT shared library | ON |
| MPMT_BUILD_TESTS | Build MPMT library tests | ON |
| MPMT_BUILD_EXAMPLES | Build MPMT usage examples | ON |
| Name | Description | Windows | macOS | Linux |
|---|---|---|---|---|
| mpmt-static | Static MPMT library | .lib | .a | .a |
| mpmt-shared | Dynamic MPMT library | .dll | .dylib | .so |
git clone https://github.com/cfnptr/mpmt
- Windows:
./scripts/build-release.bat - macOS / Linux:
./scripts/build-release.sh
Thread example: examples/thread_example.c
Mutex example: examples/mutex_example.c