[英]why can't i return array values to main function?
我在Linux中创建了一个用于创建线程的主函数,它具有读取该数据的功能。 我的主要代码包含线程的初始化:
主功能 :
int main(int argc , /*no of aruments*/
char *argv[])/*store each argument values*/
{
pthread_t thid[count];
create_thread(argv,count,&thid);
}
和我的功能:
int create_thread(char *argv[],int count , pthread_t **thid)
{
for(index = 1; index <= count; index++)
{
status = pthread_create(&thid[index],NULL,file_op,(void*) mystruct);/*create main threads*/
}
}
我得到了错误
function.c:: warning: passing argument 1 of ‘pthread_create’ from incompatible pointer type
/usr/include/pthread.h: note: expected ‘pthread_t * __restrict__’ but argument is of type ‘pthread_t **
和
main.c: In function ‘main’:
main.c:: warning: passing argument 3 of ‘create_thread’ from incompatible pointer type
function.c:: note: expected ‘pthread_t **’ but argument is of type ‘pthread_t (*)[(long unsigned int)(count)]’
线程代码有问题吗? 我如何声明正确的语法? 我想从函数到主数组获取所有值。
进行两项更改:
create_thread(argv,count,thid);
和
int create_thread(char *argv[],int count , pthread_t *thid)
这将把数组传递给你的函数,它将传递一个指向要由pthread_create更新的其中一个线程ID的指针。
pthread_create函数的第一个参数需要pthread_t *
。 你传递的错误类型的论点。
看看这个: pthread_create
此外, create_thread()
正在写入thid
数组的末尾。 循环应该是
for (index = 0; index < count; index++)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.