chapter 27: Thread API Flashcards
1
Q
Thread creation
A
pthread_create()
2
Q
what does pthread_join() do?
A
waits for a thread to complete
3
Q
what is the type of thread?
A
pthread_t
4
Q
what are the function for locks?
A
int pthread_mutex_lock(pthread_mutex_t *mutex) int pthread_mutex_unlock(pthread_mutex_t *mutex)
init
pthread_mutex_t = PTHREAD_MUTEX_INITIALIZER;
or
int rc = pthread_mutex_init(&lock, NULL);
rc == 0 if success
5
Q
what are timedlocks and trylocks?
A
int pthread_mutex_trylock(pthread_mutex_t *mutex); trylock returns failure if lock is already held
int pthread_mutex_timedlock(pthread_mutex_t *mutex, time); after acquiring a lock. returns after a timeout or finish acquiring a lock. whichever comes first.
6
Q
what are the functions for Condition Variables?
A
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); int pthread_cond_signal(pthread_cond_t *cond); note: wait takes cv and mutex. singal only takes cv.
pthread_cond_t cond = PTHREAD_COND_INITIALIZER