Go to main content

man pages section 3: Library Interfaces and Headers

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

threads.h(3HEAD)

Name

threads.h - C11 standard thread interfaces

Synopsis

#include <threads.h>

Description

The <threads.h> header file is defined in the C11 standard. It includes the macros, types, enumeration constants and functions for support of the threads interfaces as defined in that standard. The interfaces are simple wrappers over the more general pthread interfaces (see pthread.h(3HEAD)). For more information on the contents of <threads.h>, refer to INCITS/ISO/IEC 9899:2011.

The following macros are defined:

  • thread_local
  • ONCE_FLAG_INIT
  • TSS_DTOR_ITERATIONS

The macro thread_local expands to _Thread_local, which in turn expands to the type qualifier used to specify thread-local storage (TLS). Do not confuse this with thread-specific storage (TSS), also known as thread-specific data (TSD).

The following types are declared:

  • cnd_t
  • thrd_t
  • tss_t
  • mtx_t
  • tss_dtor_t
  • thrd_start_t
  • once_flag

The following enumeration constants are declared:

  • mtx_plain
  • mtx_timed
  • mtx_recursive
  • thrd_timedout
  • thrd_success
  • thrd_busy
  • thrd_error
  • thrd_nomem

The following functions are declared:

void call_once(once_flag *flag, void (*func)(void));
int cnd_broadcast(cnd_t *cond);
void cnd_destroy(cnd_t *cond);
int cnd_init(cnd_t *cond);
int cnd_signal(cnd_t *cond);
int cnd_timedwait(cnd_t *restrict cond, mtx_t *restrict mtx,
          const struct timespec *restrict ts);
int cnd_wait(cnd_t *cond, mtx_t *mtx);
void mtx_destroy(mtx_t *mtx);
int mtx_init(mtx_t *mtx, int type);
int mtx_lock(mtx_t *mtx);
int mtx_timedlock(mtx_t *restrict mtx,
          const struct timespec *restrict ts);
int mtx_trylock(mtx_t *mtx);
int mtx_unlock(mtx_t *mtx);
int thrd_create(thrd_t *thr, thrd_start_t func, void *arg);
thrd_t thrd_current(void);
int thrd_detach(thrd_t thr);
int thrd_equal(thrd_t thr0, thrd_t thr1);
_Noreturn void thrd_exit(int res);
int thrd_join(thrd_t thr, int *res);
int thrd_sleep(const struct timespec *duration,
          struct timespec *remaining);
void thrd_yield(void);
int tss_create(tss_t *key, tss_dtor_t dtor);
void tss_delete(tss_t key);
int tss_set(tss_t key, void *val);

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed

See Also

call_once(3C), cnd_init(3C), mtx_init(3C), thrd_create(3C), tss_create(3C), pthread.h(3HEAD), attributes(7)