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. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access