ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
threads.h
Go to the documentation of this file.
1/* C11 <threads.h>.
2 *
3 * ESBMC ships its own <pthread.h> operational model and puts its header
4 * directory on the -isystem path, which shadows glibc's
5 * <bits/thread-shared-types.h> with a forwarder to that model. The system
6 * <threads.h> expects the glibc original and its private types (__tss_t,
7 * __thrd_t, ...), so including it used to fail with "unknown type name
8 * '__tss_t'" on glibc and "file not found" on platforms that ship no
9 * <threads.h> at all. Provide the header ourselves, layered on the pthread
10 * model exactly as glibc layers C11 threads over pthreads. See issue #3449.
11 */
12
13#ifndef __ESBMC_THREADS_H
14#define __ESBMC_THREADS_H
15
16#include <pthread.h>
17#include <time.h>
18
19#define thread_local _Thread_local
20
21/* C11 7.26.5.1: at least 4 rounds of TSS destructor calls. */
22#define TSS_DTOR_ITERATIONS 4
23
28
29typedef int (*thrd_start_t)(void *);
30typedef void (*tss_dtor_t)(void *);
31
32typedef int once_flag;
33#define ONCE_FLAG_INIT 0
34
35enum
36{
40};
41
42enum
43{
49};
50
51int thrd_create(thrd_t *, thrd_start_t, void *);
54int thrd_sleep(const struct timespec *, struct timespec *);
55void thrd_yield(void);
56_Noreturn void thrd_exit(int);
58int thrd_join(thrd_t, int *);
59
60int mtx_init(mtx_t *, int);
61int mtx_lock(mtx_t *);
62int mtx_timedlock(mtx_t *__restrict, const struct timespec *__restrict);
63int mtx_trylock(mtx_t *);
64int mtx_unlock(mtx_t *);
65void mtx_destroy(mtx_t *);
66
67void call_once(once_flag *, void (*)(void));
68
69int cnd_init(cnd_t *);
70int cnd_signal(cnd_t *);
71int cnd_broadcast(cnd_t *);
72int cnd_wait(cnd_t *, mtx_t *);
73int cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict, const struct timespec *__restrict);
74void cnd_destroy(cnd_t *);
75
77void *tss_get(tss_t);
78int tss_set(tss_t, void *);
79void tss_delete(tss_t);
80
81#endif
Definition int.py:1
unsigned long int pthread_t
Definition pthread.h:41
unsigned int pthread_key_t
Definition pthread.h:91
Definition pthread.h:75
Definition pthread.h:50
Definition time.h:69
int tss_create(tss_t *, tss_dtor_t)
Definition threads_lib.c:189
pthread_key_t tss_t
Definition threads.h:27
int cnd_init(cnd_t *)
Definition threads_lib.c:147
int(* thrd_start_t)(void *)
Definition threads.h:29
int once_flag
Definition threads.h:32
int thrd_join(thrd_t, int *)
Definition threads_lib.c:75
int cnd_broadcast(cnd_t *)
Definition threads_lib.c:159
pthread_t thrd_t
Definition threads.h:24
@ mtx_timed
Definition threads.h:39
@ mtx_plain
Definition threads.h:37
@ mtx_recursive
Definition threads.h:38
_Noreturn void thrd_exit(int)
Definition threads_lib.c:63
@ thrd_timedout
Definition threads.h:48
@ thrd_success
Definition threads.h:44
@ thrd_busy
Definition threads.h:45
@ thrd_nomem
Definition threads.h:47
@ thrd_error
Definition threads.h:46
void tss_delete(tss_t)
Definition threads_lib.c:207
int thrd_sleep(const struct timespec *, struct timespec *)
Definition threads_lib.c:45
int mtx_init(mtx_t *, int)
Definition threads_lib.c:88
int thrd_equal(thrd_t, thrd_t)
Definition threads_lib.c:33
int cnd_wait(cnd_t *, mtx_t *)
Definition threads_lib.c:165
int mtx_lock(mtx_t *)
Definition threads_lib.c:104
void cnd_destroy(cnd_t *)
Definition threads_lib.c:183
void call_once(once_flag *, void(*)(void))
Definition threads_lib.c:141
int mtx_trylock(mtx_t *)
Definition threads_lib.c:119
void * tss_get(tss_t)
Definition threads_lib.c:195
void mtx_destroy(mtx_t *)
Definition threads_lib.c:135
int thrd_detach(thrd_t)
Definition threads_lib.c:69
pthread_cond_t cnd_t
Definition threads.h:26
int thrd_create(thrd_t *, thrd_start_t, void *)
Definition threads_lib.c:19
int tss_set(tss_t, void *)
Definition threads_lib.c:201
thrd_t thrd_current(void)
Definition threads_lib.c:39
int cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict, const struct timespec *__restrict)
void thrd_yield(void)
Definition threads_lib.c:57
int cnd_signal(cnd_t *)
Definition threads_lib.c:153
int mtx_unlock(mtx_t *)
Definition threads_lib.c:129
pthread_mutex_t mtx_t
Definition threads.h:25
int mtx_timedlock(mtx_t *__restrict, const struct timespec *__restrict)
void(* tss_dtor_t)(void *)
Definition threads.h:30