gpt4 book ai didi

c - 如何将整数分配给 pthread_create 调用的函数?

转载 作者:太空宇宙 更新时间:2023-11-04 06:33:55 25 4
gpt4 key购买 nike

给定以下代码:

void* actThread(int acc)
{
.
.
.
}
int err;
err = pthread_create(&ntid, NULL, actThread, &connfd);

我如何将 connfd 整数传递给函数 actThread。我尝试的每一种方式都会出错

最佳答案

您可以执行以下操作:

void* actThread(void* accp)
{
int acc = (int)accp;
.
.
.
}
int connfd;
int err;
err = pthread_create(&ntid, NULL, actThread, (void*)connfd);

但是,因为我假设您不知道自己在做什么,所以在应用它之前尝试学习一些关于指针的知识。

我可以向您推荐这个问题作为开始:https://stackoverflow.com/questions/4016765/tutorial-on-c-pointers

关于c - 如何将整数分配给 pthread_create 调用的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17223000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com