Bất cứ khi nào tôi có thể tạo một pthread, valgrind kết quả đầu ra rò rỉ bộ nhớ,tại sao pthread gây ra một bộ nhớ bị rò rỉ
Ví dụ đoạn code dưới đây:
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
void *timer1_function (void *eit){
(void) eit;
printf("hello world\n");
pthread_exit(NULL);
}
int main(void){
pthread_t timer1;
pthread_create(&timer1, NULL, timer1_function, NULL); ///////line13
int i=0;
for(i=0;i<2;i++){usleep(1);}
return 0;
}
đầu ra valgrind
==1395== HEAP SUMMARY:
==1395== in use at exit: 136 bytes in 1 blocks
==1395== total heap usage: 6 allocs, 5 frees, 1,134 bytes allocated
==1395==
==1395== 136 bytes in 1 blocks are possibly lost in loss record 1 of 1
==1395== at 0x402A629: calloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1395== by 0x4011304: allocate_dtv (dl-tls.c:297)
==1395== by 0x4011AAB: _dl_allocate_tls (dl-tls.c:461)
==1395== by 0x4052470: [email protected]@GLIBC_2.1 (allocatestack.c:571)
==1395== by 0x8048566: main (test.c:13)
==1395==
==1395== LEAK SUMMARY:
==1395== definitely lost: 0 bytes in 0 blocks
==1395== indirectly lost: 0 bytes in 0 blocks
==1395== possibly lost: 136 bytes in 1 blocks
==1395== still reachable: 0 bytes in 0 blocks
==1395== suppressed: 0 bytes in 0 blocks
tại sao nguyên nhân pthread_create một vấn đề mặc dù tôi đã sử dụng trang người đàn ông làm tài liệu tham khảo, và làm thế nào tôi có thể sửa nó?
có thể trùng lặp với [lỗi rò rỉ bộ nhớ valgrind khi sử dụng pthread \ _create] (http: // stackoverflow.com/questions/5610677/valgrind-memory-leak-errors-khi-sử dụng-pthread-create) – nos