为什么pthread_create()有时会在Cygwin端口上给出EAGAIN?

时间:2011-03-08 00:01:58

标签: c++ cygwin pthreads porting

当pthread_create()返回errno 11(EAGAIN),“资源暂时不可用”时,这是什么意思?

我正在将我的应用程序移植到Cygwin,因为它在Centos 4上工作得非常好。每隔一段时间,应用程序就会调用pthread_create()失败,但大部分时间它工作正常。

这意味着什么是错误的?

Linux Centos 4手册页说:

   EAGAIN The  system  lacked  the  necessary  resources  to  create  another  thread,  or  the  system-imposed  limit  on  the  total  number of threads in a process
          {PTHREAD_THREADS_MAX} would be exceeded.

我怀疑我是否正在点击PTHREAD_THREADS_MAX,那么Cygwin系统如何耗尽资源来创建另一个线程呢?

1 个答案:

答案 0 :(得分:1)

来自pthread_create() man page

如果出现以下情况,pthread_create()函数将失败:
EAGAIN
系统缺少创建另一个线程所需的资源,或者会超出系统对进程中线程总数的限制{PTHREAD_THREADS_MAX}。

在释放一些资源后,您可以再试一次。