Creating threads with the pthreads library
Let's get straight to business. You need to understand the pthread APIs we'll discuss to get your hands dirty. To start with, this function is used to create a new thread:
#include <pthread.h> int pthread_create( pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg )
The following table briefly explains the arguments used in the preceding function:
API arguments | Comments |
| Thread handle pointer |
| Thread attribute |
| Thread function pointer |
| Thread argument |
This function blocks the caller thread until the thread passed in the first argument exits, as shown in the code:
int pthread_join ( pthread_t *thread, void **retval )
The following table briefly describes the arguments in the preceding function:
API arguments | Comments |
| Thread handle |
| Output parameter that indicates... |