1:传Struct结构的指针
typedef union {
size_t arg_cnt;
any_possible_arg_types;
} arg_type;
arg_type args[ARG_NUM + 1];
args[0].arg_cnt = ARG_NUM;
args[1].xxx = ...;
pthread_create (..., ..., thread_function, &args[0]);
2:传void*[]
你创建一个void*[],里面保存指向你的所有参数的指针,然后把这个void*[]传递给pthread_create就可以了么……
多少个参数还不是随便你?给你个例子
#include <pthread.h>
void* route(void* args)
{
int* iptr = ((void**)args)[0];
float* fptr = ((void**)args)[1];
char* str = ((void**)args)[2];
printf("integer: %d/nfloat: %f/nstring: %s/n", *iptr, *fptr, str);
return 0;
}
int main(void)
{
pthread_t thr_id;
int ival = 1;
float fval = 10.0F;
char buf[] = "func";
void* arg[3]={&ival, &fval, buf};
pthread_create(&thr_id, NULL, route, arg);
sleep(1);
}