O'Reilly logo

Mastering C++ Programming by Jeganathan Swaminathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

pthread_t *thread

Thread handle pointer

pthread_attr_t *attr

Thread attribute

void *(*start_routine)(void*)

Thread function pointer

void * arg

Thread argument

This function blocks the caller thread until the thread passed in the first argument exits, as shown in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required