Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C pthread_join参数类型错误_C_Pthreads_Pthread Join - Fatal编程技术网

C pthread_join参数类型错误

C pthread_join参数类型错误,c,pthreads,pthread-join,C,Pthreads,Pthread Join,我一直在尝试创建一个简单的线程,从stdin读取数据并将输入存储到一个链表中。创建和连接线程时,我遇到以下错误: warning: passing argument 1 of ‘pthread_join’ makes integer from pointer without a cast [-Wint-conversion] pthread_join(prod_thread, NULL); 我正在将一个thread\u t*参数传递给pthread\u join,但它似乎需要一个int,

我一直在尝试创建一个简单的线程,从stdin读取数据并将输入存储到一个链表中。创建和连接线程时,我遇到以下错误:

warning: passing argument 1 of ‘pthread_join’ makes integer from pointer without a cast [-Wint-conversion]
   pthread_join(prod_thread, NULL);
我正在将一个thread\u t*参数传递给pthread\u join,但它似乎需要一个int,这让我很困惑。有人能解释为什么会这样吗?代码如下:

pair_t* head = malloc(sizeof(pair_t));
pthread_t* prod_thread = malloc(sizeof(pthread_t));
pthread_create(prod_thread, NULL, prod_func, head);
pthread_join(prod_thread, NULL);
prod_func函数如下所示:

void* prod_func(void* head) {
  ...
}
我还尝试调用
pthread\u-join(&prod\u-thread,NULL)但是我得到了同样的错误

我正在将一个thread\u t*参数传递给pthread\u join,但它似乎需要一个int,这让我很困惑

期望其第一个参数是
pthread\u t
(不是
pthread\u t*
)。具体是什么类型的
pthread\u t
因实现而异,但在您的实现中,它是一种整数类型。您正在传递一个指针

我还尝试调用pthread\u join(&prod\u thread,NULL);但后来我得到了同样的错误

你当然知道。如果
prod\u thread
具有类型
pthread\u t*
,则其地址
&prod\u thread
具有类型
pthread\u t**
。这走错了方向(结果仍然是一个指针)。在编写声明时,您实际需要的是

pthread_join(*prod_thread, NULL);
我正在将一个thread\u t*参数传递给pthread\u join,但它似乎需要一个int,这让我很困惑

期望其第一个参数是
pthread\u t
(不是
pthread\u t*
)。具体是什么类型的
pthread\u t
因实现而异,但在您的实现中,它是一种整数类型。您正在传递一个指针

我还尝试调用pthread\u join(&prod\u thread,NULL);但后来我得到了同样的错误

你当然知道。如果
prod\u thread
具有类型
pthread\u t*
,则其地址
&prod\u thread
具有类型
pthread\u t**
。这走错了方向(结果仍然是一个指针)。在编写声明时,您实际需要的是

pthread_join(*prod_thread, NULL);