Skip to content

Repository files navigation

MPMT

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.

Features

  • Mutex (Mutual exclusion)
  • Cond (Condition variable)
  • Thread (sleep, yield, etc.)
  • Thread pool (tasks)
  • Atomics (fetch add)
  • Supports Windows, macOS and Linux

Usage example

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);
}

Build requirements

Use building instructions to install all required tools and libraries.

CMake options

NameDescriptionDefault value
MPMT_BUILD_SHAREDBuild MPMT shared libraryON
MPMT_BUILD_TESTSBuild MPMT library testsON
MPMT_BUILD_EXAMPLESBuild MPMT usage examplesON

CMake targets

NameDescriptionWindowsmacOSLinux
mpmt-staticStatic MPMT library.lib.a.a
mpmt-sharedDynamic MPMT library.dll.dylib.so

Cloning

git clone https://github.com/cfnptr/mpmt

Building CI

  • Windows: ./scripts/build-release.bat
  • macOS / Linux: ./scripts/build-release.sh

Usage

Thread example: examples/thread_example.c
Mutex example: examples/mutex_example.c

About

Multi-platform multi-threading library, C99 <threads.h> alternative (mutex, cond, thread, pool)

Topics

Resources

Stars

9 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages