What does each thread get its own copy of?
Automatic variables (function variables)
What data do threads share?
Give four reasons threads are useful
How do threads increase the responsiveness of a program?
There can be separate threads for IO while others do computation.
What library implements POSIX threads?
pthreads
What is the function used to create a new thread in C?
pthread_create()
What is the function prototype of pthread_create?
int pthread_create(
pthread_t *restrict thread,
const pthread_attr_t *restrict attr,
void *(*start_routine)(void*),
void *restrict arg);What are two ways for a thread to exit?
- It calls pthread_exit
What is the function prototype for pthread_exit?
void pthread_exit(void *value_ptr);
What happens to threads when a process terminates?
They also terminate.
What function is used to get the current thread’s ID?
pthread_self
What is the function prototype for pthread_self?
pthread_t pthread_self(void);
What makes a function thread-safe?
When the correct result is produced in the face of simultaneous execution.
What gcc parameter is used to link the pthread library?
-pthread
What function is used to wait for a thread to terminate?
pthread_join
What does the pthread_join function do?
Waits for a thread to terminate and receives its return value.
What is the function prototype for pthread_join?
int pthread_join(pthread_t thread, void **value_ptr);
What function is used to request termination of another thread?
pthread_cancel
What is the function prototype of pthread_cancel?
int pthread_cancel(pthread_t thread);
What does the pthread_cancel function do?
Requests the termination of another thread.