P99
Data Structures | Modules | Defines | Typedefs | Functions
C11 thread emulation on top of POSIX threads
Emulating features of C11
+ Collaboration diagram for C11 thread emulation on top of POSIX threads:

Data Structures

struct  p99_tss
 A stub structure to hold a thread local variable if thread_local is not available. More...

Modules

 Thread_macros
 Thread_types
 Thread_enum

Defines

#define p99_call_once(FLAG, FUNC, ARG)
 Call a function FUNC exactly once, optionally providing it with argument ARG.
#define P99_DECLARE_ONCE_CHAIN(T)   extern p99_once_flag P99_PASTE3(p99_, T, _once)
 Declare the symbols that are needed for the macro P99_INIT_CHAIN().
#define P99_DECLARE_THREAD_LOCAL   P99_TSS_DECLARE_LOCAL
 declare a thread local variable NAME of type T
#define P99_DEFINE_ONCE_CHAIN(T,...)
 Define a function that will be called exactly once by P99_INIT_CHAIN(T).
#define P99_INIT_CHAIN(T)   p99_call_once(&P99_PASTE3(p99_, T, _once), P99_PASTE3(p99_, T, _once).p00_init)
 Ensure that the function that was defined with P99_DEFINE_ONCE_CHAIN has been called exactly once before proceeding.
#define P99_MUTUAL_EXCLUDE(MUT)
 Protect the following block or statement with mtx_t MUT.
#define P99_THREAD_LOCAL   P99_TSS_LOCAL
 an lvalue expression that returns the thread local instance of variable NAME
#define P99_TSS_DECLARE_LOCAL(T, NAME, DTOR)
 declare a thread local variable NAME of type T and with destructor DTOR.
#define P99_TSS_LOCAL(NAME)   (*(P99_PASTE3(p00_, NAME, _type)*)p99_tss_get_alloc(&(NAME), sizeof(P99_PASTE3(p00_, NAME, _type))))
 an lvalue expression that returns the thread local instance of variable NAME

Typedefs

typedef struct p99_tss p99_tss

Functions

int cnd_broadcast (cnd_t *p00_cond)
void cnd_destroy (cnd_t *p00_cond)
int cnd_init (cnd_t *p00_cond)
int cnd_signal (cnd_t *p00_cond)
int cnd_timedwait (cnd_t *restrict p00_cond, mtx_t *restrict p00_mtx, const struct timespec *restrict p00_ts)
int cnd_wait (cnd_t *p00_cond, mtx_t *p00_mtx)
void mtx_destroy (mtx_t *p00_mtx)
int mtx_init (mtx_t *p00_mtx, int p00_type)
int mtx_lock (mtx_t *p00_mtx)
int mtx_timedlock (mtx_t *restrict p00_mtx, const struct timespec *restrict p00_ts)
int mtx_trylock (mtx_t *p00_mtx)
int mtx_unlock (mtx_t *p00_mtx)
int p99_threads_main (int, char *[])
 A replacement name for the users main function, experimental.
void p99_tss_delete (p99_tss *p00_key)
 Similar to tss_delete.
void * p99_tss_get (p99_tss *p00_key)
 Similar to tss_get.
void * p99_tss_get_alloc (p99_tss *p00_key, size_t p00_size)
 Similar to p99_tss_get, but also allocates a buffer of p00_size bytes for p00_key.
int p99_tss_set (p99_tss *p00_key, void *p00_val)
 Similar to tss_set(p00_key, p00_val) but also calls the destructor on the previous value if necessary.
int thrd_create (thrd_t *p00_thr, thrd_start_t p00_func, void *p00_arg)
thrd_t thrd_current (void)
int thrd_detach (thrd_t p00_thr)
int thrd_equal (thrd_t p00_thr0, thrd_t p00_thr1)
void thrd_exit (int p00_res)
void thrd_yield (void)
int tss_create (tss_t *p00_key, tss_dtor_t dtor)
void tss_delete (tss_t p00_key)
void * tss_get (tss_t p00_key)
int tss_set (tss_t p00_key, void *p00_val)

Detailed Description

This is a relatively straightforward implementation of the C11 thread model on top of POSIX threads. The main difficulty this presents is that the thread entry function signature differs between the two. C11 thread returns an int whereas POSIX returns a void*.

You can find the thread management interfaces through the documentation of the type thrd_t.

Remarks:
In addition to POSIX threads this implementation needs some C11 atomic operations for initialization via ::call_once and status communication.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines