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)
void mutexExample()
{
Mutex mutex = createMutex();
if (!mutex)
abort();
lockMutex(mutex);
// Do some synchronized work...
unlockMutex(mutex);
destroyMutex(mutex);
}
// ========================================
static void onUpdate(void* arument)
{
volatile bool* isRunning = argument;
while (*isRunning)
{
// Do some parallel work...
sleepThread(0.001);
}
}
void threadExample()
{
volatile bool isRunning = true;
Thread thread = createThread(
onUpdate, &isRunning);
if (!thread)
abort();
isRunning = false;
joinThread(thread);
destroyThread(thread);
}
- Windows
- macOS
- Ubuntu (Linux)
- C99 compiler
- C++17 compiler (optional)
- Git 2.30+
- 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 / Ubuntu:
./scripts/build-release.sh
Thread example: examples/thread_example.c
Mutex example: examples/mutex_example.c