Because the interface defines only one entry void *arg
int pthread_create (pthread_t *tidp,const pthread_attr_t *attr, (void*) (*START_RTN) (void*), void *arg);
Therefore, if you want to pass parameters, you need to encapsulate the structure and pass multiple parameters to the thread through a struct.
typedef struct{ FUNCPTR entry;/* Function entry * /void *arg[10];/* parameter */}func;void *start (void *arg) { FUNC *func = NULL ; (* (Func->entry)) (Func->arg[0], func->arg[1], func->arg[2], func->arg[3], func->arg[4], func->arg[5], func- >ARG[6], func->arg[7], func->arg[8], func->arg[9]); return NULL;} int pthread_ctreate (pthread_t *tidp,const pthread_attr_t *attr, void * (*FUNCPTR) (void *, void *, void *), unsigned args,. ..) {/ * struct Body of constructor collection */ FUNC function = {0}; Function.entry = funcptr; for (i = 0; i < args; i++) { Func->arg[i] = Arg[i]; } Set thread properties (slightly) pthread_create (NULL, &attr, start, (void *) &function);
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Pthread_create () pass in more than one parameter when creating a thread