免费注册 查看新帖 |

Chinaunix

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

线程中再开线程会有问题不? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-02-08 11:24 |只看该作者 |倒序浏览
一这样做内存就不停的涨,注释了就没事,是不是要做什么回收?

论坛徽章:
0
2 [报告]
发表于 2012-02-08 11:31 |只看该作者
每次8M   网上搜是线程堆栈8M

论坛徽章:
0
3 [报告]
发表于 2012-02-08 12:11 |只看该作者

论坛徽章:
0
4 [报告]
发表于 2012-02-08 15:24 |只看该作者
  1. PTHREAD_DETACH(3)                          Linux Programmer's Manual                          PTHREAD_DETACH(3)

  2. NAME
  3.        pthread_detach - detach a thread

  4. SYNOPSIS
  5.        #include <pthread.h>

  6.        int pthread_detach(pthread_t thread);

  7.        Compile and link with -pthread.

  8. DESCRIPTION
  9.        The pthread_detach() function marks the thread identified by thread as detached.  When a detached thread
  10.        terminates, its resources are automatically released back to the system without  the  need  for  another
  11.        thread to join with the terminated thread.

  12.        Attempting to detach an already detached thread results in unspecified behavior.

复制代码

论坛徽章:
0
5 [报告]
发表于 2012-02-08 15:32 |只看该作者
个人观点,posix应该去除 pthread_detach 这个函数,
迫使程序员负责回收每一个线程。

论坛徽章:
0
6 [报告]
发表于 2012-02-08 17:44 |只看该作者
反正团队里面的规范,要求禁止用pthread_detach,创建线程、外面等待线程结束,要按规定流程来使用

从标准的角度来看,多提供一些选择也无不可,但要求使用者要合理选择。

windows还提供SuspendThread,TerminateThread之类的,都是要禁止使用的。

论坛徽章:
1
白羊座
日期:2013-09-18 22:02:26
7 [报告]
发表于 2012-02-09 09:20 |只看该作者
posix的pthread编程中在创建thread时可以设置属性为自动回收。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP