gpt4 book ai didi

调用 C 中的特定线程

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

在我的多线程项目中,我有多个线程同时运行,我能找到的唯一等待函数是 pthread_join 但它不调用特定线程,而是阻塞当前运行的线程,直到我作为参数传递给的线程pthread_join 结束了。我正在寻找一种调用特定方法的方法。

typedef struct proc{
int sys_number; //unique node ID i give the thread
pthread_t process;
} thread;

thread proccesses[N];

thread = pthread_create(&(proccesses[i].process), NULL, printme, &(proccesses[i].sys_number));

然后当我想调用 processes[i].process 我使用:

pthread_join(proccesses[0].process, &status);

但它运行所有已打开和等待的进程,我正在寻找进程中的 waitpid 等价物。

编辑:我正在寻找一种方法来选择接下来要运行的线程

最佳答案

我相信您可以通过互斥锁和条件变量为每个线程实现一个简单的 pause()/resume() Controller 。

关于调用 C 中的特定线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20180386/

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