Multithread#
Thin wrappers around the POSIX threading primitives, plus a memory pool and a producer-consumer queue built on them. Every module here is thread-safe by design, and POSIX-only: none of it is available in bare-metal builds.
Note
To use caller-supplied storage for a primitive’s handle, pass it with
RCSW_NOALLOC_HANDLE. Without that flag the handle argument is
ignored (NULL is fine) and the library allocates one. See
Memory Model.
Primitives#
Module |
Notes |
Link |
|---|---|---|
Mutex |
Wrapper around POSIX mutexes ( |
|
Condition variable |
Wrapper around POSIX condition variables ( |
|
Condition variable / mutex pair |
Convenience wrapper combining |
|
Binary semaphore |
Built on |
|
Counting semaphore |
Wrapper around POSIX semaphores ( |
|
Fair reader/writer lock |
Guarantees that neither readers nor writers will starve. Uses three
|
Higher-Level Constructs#
Module |
Notes |
Link |
|---|---|---|
Memory pool |
Thread-safe fixed-size block allocator. Used by threads to
request/release memory chunks of a specified size. Reference-counted;
a block is returned to the pool only when all holders have released
it. |
|
Producer-consumer queue |
Blocking FIFO queue supporting multiple producers and consumers. Internally synchronized; callers do not need additional locking. |
Thread Management#
#include "rcsw/multithread/threadm.h"
threadm_core_lock() pins a thread to a CPU core. Like the rest of this
module it is POSIX-only; it uses pthread_setaffinity_np(), so it needs
Linux or another platform that provides it.
For timeouts and what is safe to call concurrently, see Concurrency.