François Trahay
a0
rax
Execution flow ! = Resources
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
attr
start_routine
arg
thread
int pthread_exit(void* retval);
retval
int pthread_join(pthread_t tid, void **retval);
tid
fread
errno
_Thread_local int variable = 0;
x++
load
update
store
swap(a, b){ tmp=a; a=b; b=tmp; }
Type: pthread_mutex_t
pthread_mutex_t
Initialisation:
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
int pthread_mutex_init(ptread_mutex_t *m, const pthread_mutexattr_t *attr);
Usage:
int pthread_mutex_lock(pthread_mutex_t *mutex));
int pthread_mutex_trylock(pthread_mutex_t *mutex);
int pthread_mutex_unlock(pthread_mutex_t *mutex);
Terminaison:
int pthread_mutex_destroy(pthread_mutex_t *mutex);
Operation executed atomically
C11 defines a set of functions that perform atomic operations
C atomic_fetch_add(volatile A *object, M operand);
_Bool atomic_flag_test_and_set(volatile atomic_flag *object);
C11 defines atomic types
_Atomic int var;
_Atomic(int) var;