pthread_create和EAGAIN [英] pthread_create and EAGAIN

查看:154
本文介绍了pthread_create和EAGAIN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用pthread_create生成线程时,我得到了一个EAGAIN.但是,从我检查的结果来看,线程似乎已正确终止.

I got an EAGAIN when trying to spawn a thread using pthread_create. However, from what I've checked, the threads seem to have been terminated properly.

当尝试使用pthread_create创建线程时,由什么决定操作系统赋予EAGAIN?

What determines the OS to give EAGAIN when trying to create a thread using pthread_create? Would it be possible that unclosed sockets/file handles play a part in causing this EAGAIN (i.e they share the same resource space)?

最后,是否有任何工具可以检查资源使用情况,或者可以使用任何函数查看当时有多少个pthread对象处于活动状态?

And lastly, is there any tool to check resource usage, or any functions that can be used to see how many pthread objects are active at the time?

推荐答案

好的,找到答案了.即使调用了pthread_exit或pthread_cancel,父进程仍需要调用pthread_join来释放pthread ID,然后该ID将变为可回收的.

Okay, found the answer. Even if pthread_exit or pthread_cancel is called, the parent process still need to call pthread_join to release the pthread ID, which will then become recyclable.

最后放一个pthread_join(tid,NULL)可以解决问题.

Putting a pthread_join(tid, NULL) in the end did the trick.

编辑(不是waitpid,而是pthread_join)

edit (was not waitpid, but rather pthread_join)

这篇关于pthread_create和EAGAIN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆