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原因如上

  • 相关阅读:
    Android四大基本组件介绍与生命周期
    论Android产品高效开发之路
    android工程目录分析
    android推送思路
    android类库
    Android实现应用下载并自动安装apk包
    自定义 Android 对话框 (AlertDialog) 的样式
    Android adb shell 命令详解
    Complexities
    Combination Sum II
  • 原文地址:https://www.cnblogs.com/Call-C/p/6105092.html
Copyright © 2011-2022 走看看