64,663
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <pthread.h>
#include <vector>
using namespace std;
void* thread_func(void* args)
{
return 0;
}
int main(int argc,char *argv[])
{
if(argc!=2)
{
cout<<"Run with:"<<argv[0]<<" thread_count"<<endl;
return -1;
}
unsigned int NUM_THREADS= atoi(argv[1]);
pthread_t tids[NUM_THREADS];
for(int i = 0; i < NUM_THREADS; ++i)
{
int ret = pthread_create(&tids[i], NULL, thread_func, NULL);
if (ret != 0)
{
sleep(2);
cout << "pthread_create error: error_code=" << ret << endl;
}
}
pthread_exit(NULL);
}
==12919== Memcheck, a memory error detector
==12919== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==12919== Using Valgrind-3.8.0 and LibVEX; rerun with -h for copyright info
==12919== Command: /etc/SU/leak 10
==12919== Parent PID: 20231
==12919==
==12919==
==12919== HEAP SUMMARY:
==12919== in use at exit: 2,880 bytes in 10 blocks
==12919== total heap usage: 15 allocs, 5 frees, 5,384 bytes allocated
==12919==
==12919== 2,880 bytes in 10 blocks are possibly lost in loss record 1 of 1
==12919== at 0x4C266D5: calloc (vg_replace_malloc.c:593)
==12919== by 0x4011892: _dl_allocate_tls (in /lib64/ld-2.12.so)
==12919== by 0x4E35068: pthread_create@@GLIBC_2.2.5 (in /lib64/libpthread-2.12.so)
==12919== by 0x400B62: main (in /leak)
==12919== by 0x5809CDC: __libc_start_main (in /lib64/libc-2.12.so)
==12919== by 0x400948: ??? (in /leak)
==12919== by 0x7FF000737: ???
==12919== by 0x1B: ???
==12919== by 0x1: ???
==12919== by 0x7FF0009DA: ???
==12919== by 0x7FF0009E7: ???
==12919==
==12919== LEAK SUMMARY:
==12919== definitely lost: 0 bytes in 0 blocks
==12919== indirectly lost: 0 bytes in 0 blocks
==12919== possibly lost: 2,880 bytes in 10 blocks
==12919== still reachable: 0 bytes in 0 blocks
==12919== suppressed: 0 bytes in 0 blocks
==12919==
==12919== For counts of detected and suppressed errors, rerun with: -v
==12919== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)