MintSystem is a portable API for thread creation, semaphores, time and date services, sleep, and thread and process IDs. Basically, the system services you need in order to run lock-free code in the first place, plus a few extras. If your project requires a more complete set of PThreads functionality, and you still want Windows compatibility, you might be interested in the PThreads-Win32 project.
To use MintSystem in your project, add the top-level
include/ folder to your include path, then include the appropriate headers such as
<mintsystem/thread.h>. To use MintSystem on UNIX-like platforms, including Linux, MacOS or iOS, you must also compile and link using the
On all platforms, you must also compile and link with a lib built from the appropriate source in the
src/mintsystem/ folder. There’s a
CMakeLists.txt located there, so you can use CMake to generate this lib for you. See the tests for some examples of how it’s used.
mint_thread_t is an opaque pointer type which represents a handle to the thread. The first argument to
mint_thread_create is actually a pointer to a pointer which receives the new handle.
You can use the following functions to create, manipulate and destroy semaphores. These are different from POSIX semaphores, though they share a similar API.
These functions provide unnamed semaphores even on Apple operating systems, which do not natively support them. Since the semaphores are unnamed, they cannot be shared between different processes.
Unlike a POSIX semaphore,
mint_sem_wait is guaranteed never to return early with an
EINTR error due to a signal interrupt. It is presumed that nobody using Mintomic semaphores will care about signal interrupts. On several platforms, including some configurations of Xcode and iOS, every debug event causes a signal interrupt, which would otherwise break the logic of the application being debugged. Mintomic semaphores protect you from this particular surprise.
Mintomic provides portable functions for low-overhead, high-resolution timers suitable for timing sections of code in the 0.5 microsecond range and up.
mint_timer_initialize only initializes the conversion ratios
mint_timer_secondsToTicks, which are provided for convenience. You can safely call any other function without calling
mint_timer_tick_t values. You can subtract these values to obtain timing deltas, then convert them to and from seconds by using the convenience conversion ratios. Use
mint_timer_greater_or_equal to determine whether
b is not earlier than
a in time; it handles wrap-around. Call
mint_timer_getSecondsToTicks to obtain the conversion ratio without calling
mint_timer_initialize first; it queries the value from the system each time.
Sleep for a specified number of milliseconds.
On systems where cores have two hardware threads,
mint_yield_hw_thread will generate a CPU instruction to yield to the other hardware thread. Thread Synchronizer uses this internally.
Date and Time
mint_get_current_utc_time returns the number of microseconds since January 1, 1601 in Coordinated Universal Time (UTC). MintPack’s
Random uses this internally.
Thread and Process IDs
You can lookup the current thread and process IDs. These basically return the values you’d expect on each platform. On Xbox 360,
mint_get_current_process_id always returns 0.