gpt4 book ai didi

c++ - 如果线程在调用 pthread_join 之前退出怎么办

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:14:00 24 4
gpt4 key购买 nike

我有一个小代码

void *PrintHello(void *threadid)
{
cout<<"Hello"<<endl;
pthread_exit(NULL);
}

int main ()
{
pthread_t threads_id;
pthread_create(&threads_id, NULL, PrintHello, NULL);
int i=0;
for(;i<100;i++){cout<<"Hi"<<endl;}
pthread_join(threads_id,NULL);
return 0;
}

我会在创建后的某个时间加入线程。如果 main 试图加入一个已经退出的线程,会发生什么?

最佳答案

What will happen if the main tries to join a thread which already exited?

连接操作将立即完成并返回。

关于c++ - 如果线程在调用 pthread_join 之前退出怎么办,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29314738/

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