Download Basic Thread Functions - Advanced Unix Programming - Lecture Slides and more Slides Computer Programming in PDF only on Docsity!
Week 11 Topics
Threads
Basic thread functions
Some more thread functions
Thread-specific data
Mutual exclusion
Conditional variables
Basic thread functions
Thread creation int pthread_create(pthread_t *thread, constpthread_attr_t *attr, void (start_routine)(void *),void * arg) - Thread attributes (stack size, scheduling policy) can be modified - Use NULL for default - Returns 0 if successful, and an error number if it fails - EAGAIN: System lacks resources - EINVAL: Invalid attribute - EPERM: Caller does not have appropriate permission - Pthread functions return error values - They do not set errno - New thread executes the function given by start_routine - arg is the argument to this function - The thread ID is stored in *thread