Thread Creation
Explore the process of creating threads using the POSIX Thread API. Understand how to initialize threads with pthread_create, use function pointers for thread routines, and pass arguments efficiently to build multi-threaded programs.
We'll cover the following...
We'll cover the following...
The first thing you have to be able to do to write a multi-threaded program is to create new threads, and thus some kind of thread creation interface must exist. In POSIX, it is easy:
Explanation
This declaration might look a little complex (particularly if you haven’t used function pointers in C), but actually it’s not too bad. There are four arguments:
threadattrstart_routinearg
The first, thread, is a pointer to a structure of type pthread_t ...