chapter 27: Thread API Flashcards

1
Q

Thread creation

A

pthread_create()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what does pthread_join() do?

A

waits for a thread to complete

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is the type of thread?

A

pthread_t

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly