码迷,mamicode.com
首页 > 编程语言 > 详细

c++ thread

时间:2016-11-26 22:48:35      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:each   cat   release   原因   ack   没有   orm   not   create   

Either pthread_join(3) or pthread_detach() should be called for each thread,that an application creates, so that system resources for the thread can be
released. (But note that the resources of all threads are freed when the process terminates.)
也就是说:每个进程创建以后都应该调用pthread_join 或 pthread_detach 函数,只有这样在线程结束的时候资源(线程的描述信息和stack)才能被释放.
之后又查了pthread_join 但是没有明确说明必须调用pthread_join 或 pthread_detach.但是再查了 Pthread for win32 pthread_join
When a joinable thread terminates, its memory resources (thread descriptor and stack) are not deallocated until another thread performs pthread_join on it. Therefore, pthread_join must be called once for each joinable thread created to avoid memory leaks.

才知道如果在新线程里面没有调用pthread_join 或 pthread_detach会导致内存泄漏, 如果你创建的线程越多,你的内存利用率就会越高, 直到你再无法创建线程,最终只能结束进程。

 1.在创建thread时候线程就开始执行了,而为什么join与detach原因如上

c++ thread

标签:each   cat   release   原因   ack   没有   orm   not   create   

原文地址:http://www.cnblogs.com/Call-C/p/6105092.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!