https://github.com/cfnptr/mpmt
Multi-platform multi-threading library, C99 <threads.h> alternative (mutex, cond, thread, pool)
https://github.com/cfnptr/mpmt
atomic c cmake condition-variable cpp cross-platform library linux macos multi-platform multi-threading mutex open-source pool pthreads thread ubuntu windows winthread
Last synced: about 4 hours ago
JSON representation
Multi-platform multi-threading library, C99 <threads.h> alternative (mutex, cond, thread, pool)
- Host: GitHub
- URL: https://github.com/cfnptr/mpmt
- Owner: cfnptr
- License: apache-2.0
- Created: 2020-11-24T10:47:33.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2026-04-06T15:01:08.000Z (about 6 hours ago)
- Last Synced: 2026-04-06T16:29:15.847Z (about 5 hours ago)
- Topics: atomic, c, cmake, condition-variable, cpp, cross-platform, library, linux, macos, multi-platform, multi-threading, mutex, open-source, pool, pthreads, thread, ubuntu, windows, winthread
- Language: C
- Homepage:
- Size: 499 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# MPMT
A small [library](https://github.com/cfnptr/mpmt) providing generic interface for **multithreading** across different platforms.
Created due to the fact that macOS does not support `` in C11.
See the [documentation](https://cfnptr.github.io/mpmt).
## Features
* Mutex (Mutual exclusion)
* Cond (Condition variable)
* Thread (sleep, yield, etc.)
* Thread pool (tasks)
* Atomics (fetch add)
* Supports Windows, macOS and Linux
## Usage example
```c
void mutexExample()
{
Mutex mutex = createMutex();
if (!mutex)
abort();
lockMutex(mutex);
// Do some synchronized work...
unlockMutex(mutex);
destroyMutex(mutex);
}
// ========================================
static void onUpdate(void* argument)
{
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);
}
```
## Build requirements
* C99 compiler
* C++17 compiler (optional)
* [Git 2.53+](https://git-scm.com/)
* [CMake 3.10+](https://cmake.org/)
Use building [instructions](BUILDING.md) to install all required tools and libraries.
### CMake options
| 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` |
### CMake targets
| Name | Description | Windows | macOS | Linux |
|-------------|----------------------|---------|----------|-------|
| mpmt-static | Static MPMT library | `.lib` | `.a` | `.a` |
| mpmt-shared | Dynamic MPMT library | `.dll` | `.dylib` | `.so` |
## Cloning
```
git clone https://github.com/cfnptr/mpmt
```
## Building 
* Windows: ```./scripts/build-release.bat```
* macOS / Linux: ```./scripts/build-release.sh```
## Usage
Thread example: [examples/thread_example.c](examples/thread_example.c)
Mutex example: [examples/mutex_example.c](examples/mutex_example.c)