难以通过pthread_create传递struct

Chu*_*cky 2 c struct pthreads createthread

我有一个结构数组,我打算在for循环中将数组的每个元素传递给单独的pthreads.

这是我的结构:

struct arrayData{
int *a;
int *b;
int up, low;
}
Run Code Online (Sandbox Code Playgroud)

}

这是指向第一个结构和一个malloc的指针(dunno,如果我完全了解这里发生的事情):

struct arrayData * instance;
        instance = malloc(sizeof(struct arrayData)*n);
Run Code Online (Sandbox Code Playgroud)

这是我对pthread_create的调用:

pthread_create( &thread[i], NULL, add, (void *)instance[i]);
Run Code Online (Sandbox Code Playgroud)

对于该行,我收到消息"无法转换为指针类型".

这条线有什么问题?

Mat*_*ert 6

您正在尝试将结构转换为最后一个参数中的指针.你需要传递struct的地址&.

pthread_create( &thread[i], NULL, add, &instance[i]);
Run Code Online (Sandbox Code Playgroud)

正如约根森所提到的,void *演员阵容是不必要的.