zoukankan      html  css  js  c++  java
  • c++ thread

    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#-WPF线程中如何修改值
    记录MySql错误消息
    记录C#-WPF布局面板
    记录TortoiseGit=>https请求/ssh请求配置
    工具-Xmind常用快捷键/使用
    记录C#泛型
    记录console的使用
    记录Flex布局的属性
    Spark的Monitoring
    HBase安装学习
  • 原文地址:https://www.cnblogs.com/Call-C/p/6105092.html
Copyright © 2011-2022 走看看