Skip to content

mulle-concurrent/mulle-thread

Repository files navigation

mulle-thread

🔠 Cross-platform thread/mutex/tss/atomic operations in C

mulle-thread

🔠 Cross-platform thread/mutex/tss/atomic operations in C

mulle-thread is a set of C wrapper headers for a simplified subset of thread functions and for a limited range of atomic operations that strongly mimics the thread standard, even if thread is not available. On Windows it has to do a bit more work.

mulle-threads main advantages are simplicity, portability, sanity.

  • basic atomic operations CAS, ++, -- on void pointers.
  • basic thread operations
  • mutex functionality
  • thread local storage, with proper destruction

Since thread has <stdatomic.h> and <threads.h>, eventually this project could become superflous. In the meantime though it's a convenient abstraction on threads and atomic operations.

Warning

mulle_thread_once doesn't guarantee, that exceptions or thread cancellation within the init function will clear the once flag for a second run. In fact it will not.

Release Version
Build Status Mulle kybernetiK tag
Release Version Release Notes
Mulle kybernetiK tag Build Status RELEASENOTES

API

Convenience macro for mutex

An easy way to get a locked code region is to use:

void   foo( mulle_thread_mutex_t *mutex)
{
   mulle_thread_mutex_do( mutex)
   {
      // code block is now executed with mutex locked
   }
   // mutex is unlocked again
}

break and continue will exit the block and unlock the mutex. But when you use return the function exists and the mutex remains locked.

You are here

Overview

Add

This project is a component of the mulle-core library. As such you usually will not add or install it individually, unless you specifically do not want to link against mulle-core.

Add as an individual component

Use mulle-sde to add mulle-thread to your project:

mulle-sde add github:mulle-concurrent/mulle-thread

To only add the sources of mulle-thread with dependency sources use clib:

clib install --out src/mulle-concurrent mulle-concurrent/mulle-thread

Add -isystem src/mulle-concurrent to your CFLAGS and compile all the sources that were downloaded with your project.

Install

Install with mulle-sde

Use mulle-sde to build and install mulle-thread and all dependencies:

mulle-sde install --prefix /usr/local \
   https://github.com/mulle-concurrent/mulle-thread/archive/latest.tar.gz

Manual Installation

Install the requirements:

Requirements Description
mulle-c11 🔀 Cross-platform C compiler glue (and some cpp conveniences)

Download the latest tar or zip archive and unpack it.

Install mulle-thread into /usr/local with cmake:

cmake -B build \
      -DCMAKE_INSTALL_PREFIX=/usr/local \
      -DCMAKE_PREFIX_PATH=/usr/local \
      -DCMAKE_BUILD_TYPE=Release &&
cmake --build build --config Release &&
cmake --install build --config Release

Author

Nat! for Mulle kybernetiK