免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6843 | 回复: 3
打印 上一主题 下一主题

pthread_create 时报Resource temporarily unavailable? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-11-03 10:14 |只看该作者 |倒序浏览
请教我在程序中,为同一IP的list分配一个线程去处理,然后用pthread_join去等待它们执行结束,上述过程每隔1分钟循环一次,但是随着时间的增加,大概几个小时过去后再次分配线程就报Resource temporarily unavailable的错误,但是之前的线程我都是用pthread_join等它们结束后才再分配的,部分代码如下:

while (10) {
    for (i = 0; i < emv_list_len(pIPList); i++) {
           pIP = emv_list_get(pIPList, i);
           if (pIP) {
        emv_debug("pIP = %s\n",pIP);
        pList = list_search_all(gMibList, (void *)pIP, list_objip_matches);
        if (pList) {
                       emv_debug("start_mib_pthread ():pList's length = %d", emv_list_len(pList));
                       iRetCode = pthread_create(&tid, NULL, mib_pthread, (void *)pList);
                       if (iRetCode != 0) {
                             emv_error("pthread_create failed: %s", strerror(iRetCode));
                       } else {
                             emv_debug("tid = %u\n",(unsigned int)tid);
                             pt = (pthread_t *)malloc(sizeof(pthread_t));
                             *pt = tid;
                             emv_list_append(pPthreadList, pt);
                        }
                }
           }
           pList = NULL;
           pt = NULL;
    }
    for (i = 0; i < emv_list_len(pPthreadList); i++) {
          pt = (pthread_t *)emv_list_get(pPthreadList,i);
          if (pt) {
                 pthread_join(*pt, NULL);
           }
           pt = NULL;
    }

     sleep(60);
}

请教为什么会这样?多谢

[ 本帖最后由 tommyli 于 2006-11-3 10:15 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2006-11-03 13:38 |只看该作者
你可以在线程函数里面用 pthread_detach()函数 来,让线程在自己结束的时候,释放资源。就不用使用pthread_join()来回收资源了。

论坛徽章:
0
3 [报告]
发表于 2006-11-07 15:49 |只看该作者
谢谢楼上的
我发现了我的错误

论坛徽章:
0
4 [报告]
发表于 2006-11-07 21:27 |只看该作者

我想搂住可能没有pthread_exit() 吧!

我想搂住可能没有pthread_exit() 吧!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP