简体   繁体   English

C编程中的pthread内存泄漏

[英]pthread memory leak in C programming

I have the code below. 我有下面的代码。

void *timer1_function(void * eit);
pthread_t timer1;
int thread_check1 = 0;

line72: thread_check1 = pthread_create( &timer1, NULL, timer1_function,  NULL);

Valgrind shows the output below and says that there is a problem in the line 72 . Valgrind在下面显示输出,并说line 72有问题。 what is wrong with the pthread_create usage above? 上面的pthread_create用法有什么问题?

272 bytes in 1 blocks are possibly lost in loss record 2 of 5
  in main in main.c:72
  1: calloc in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
  2: _dl_allocate_tls in /build/buildd/eglibc-2.15/elf/dl-tls.c:297
  3: pthread_create@@GLIBC_2.2.5 in /build/buildd/eglibc-2.15/nptl/allocatestack.c:571
  4: main in <a href="file:///home/user/Project-build-desktop-Qt_4_8_1_in_PATH__System__Release/../project/main.c:72" >main.c:72</a>

When you create a thread, you allocate some memory with it. 创建线程时,将为其分配一些内存。 The task of cleaning up this memory is done through a call to pthread_join . 清理此内存的任务是通过调用pthread_join

The reason this memory is not cleaned up upon thread exit is that these data contain information such as "thread's exit status", which the parent may want to check out later. 线程退出时未清除此内存的原因是这些数据包含诸如“线程的退出状态”之类的信息,父级可能希望稍后检出这些信息。 Therefore, never join ing the thread means never cleaning up that memory. 因此,永不join线程意味着永不清除该内存。

The concept of un-joined threads are similar to zombie processes . 未连接线程的概念类似于僵尸进程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM