Parameter passing

Recall the signature of the pthread_create(3) API:

int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);

The third parameter is the thread function—in effect, the life and scope of the newly born thread. It receives a single parameter of type void *; this parameter to the new born thread is passed via the fourth parameter to pthread_create: void *arg.

As mentioned earlier, its data type is a generic pointer, precisely so that we can, in effect, pass along any data type as a parameter, and then in the thread routine, appropriately typecast and use it. Until now, we have come across simple use cases of the same – typically, passing along an integer value as the parameter. ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.