Thread Creation
This lesson introduces you to the process of the creation of a thread.
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:
Press + to interact
#include <pthread.h>intpthread_create(pthread_t *thread,const pthread_attr_t *attr,void *(*start_routine)(void*),void *arg);
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:
thread
attr
start_routine
arg
The first, thread
, is a pointer to a structure of type pthread_t
...