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

Modules

 Thread_macros
 
 Thread_types
 
 Thread_enum
 

Data Structures

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

Macros

#define main   p99_threads_main
 
#define P99_DECLARE_THREAD_LOCAL   P99_TSS_DECLARE_LOCAL
 declare a thread local variable NAME of type T More...
 
#define P99_DECLARE_THREAD_LOCAL_EXTERN   P99_TSS_DECLARE_LOCAL_EXTERN
 
#define P99_DEFINE_THREAD_LOCAL   P99_TSS_DEFINE_LOCAL
 
#define P99_THREAD_LOCAL   P99_TSS_LOCAL
 an lvalue expression that returns the thread local instance of variable NAME More...
 
#define P99_TSS_DECLARE_LOCAL(T, NAME, DTOR)
 declare a thread local variable NAME of type T and with destructor DTOR. More...
 
#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 More...
 

Typedefs

typedef struct p99_tss p99_tss
 

Functions

 P99_MAIN_INTERCEPT (p99_threads_main)
 
 P99_SETJMP_INLINE (p00_thrd_create) void *p00_thrd_create(void *p00_context)
 
int p99_threads_main (int, char *[])
 A replacement name for the users main function, experimental. More...
 
void p99_tss_delete (p99_tss *p00_key)
 Similar to tss_delete. More...
 
void * p99_tss_get (p99_tss *p00_key)
 Similar to tss_get. More...
 
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. More...
 
p99_tssp99_tss_init (p99_tss *p00_el, tss_dtor_t p00_f)
 
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. More...
 
 P99_WEAK (p00_foreign_nb) atomic_size_t p00_foreign_nb
 
 P99_WEAK (p00_foreign_tab) p00_thrd **p00_foreign_tab
 
 P99_WEAK (p00_foreign_cleanup) void p00_foreign_cleanup(void)
 
 P99_WEAK (p00_threads_main) int p00_threads_main(void *p00_arg)
 
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.