简体   繁体   English

当所有线程未终止时,Valgrind输出

[英]Valgrind output when all the threads do not terminate

It is more of a general query, what would be the behaviour of valgrind memcheck if some of the threads spawned do not gracefully terminate. 更多的是一般查询,如果产生的某些线程没有正常终止,那么valgrind memcheck的行为是什么。 I mean the case when the threads are detached and do not share any memory with parent process/ thread. 我的意思是当线程分离并且不与父进程/线程共享任何内存时。

I dont have any code snippet or valgrind output, as it is a question just out of curiosity 我没有任何代码片段或valgrind输出,因为出于好奇,这是一个问题

For this piece of code: 对于这段代码:

while (1) {
    pthread_t thread;
    struct sockaddr_in client;
    socklen_t len = sizeof(client);
    int newsock = accept(sock, (struct sockaddr *)&client, &len);

    if (newsock == -1) {
        perror("accept");
    } else {
        if (pthread_create(&thread, NULL, handle, &newsock) != 0) {
            perror("pthread_create");
        } else {
            pthread_detach(thread);
        }
    }
    if (count == 5) break;
}
close(sock);
exit(EXIT_SUCCESS);

Where a thread is still waiting for accept() , it shows a possibly lost: 在线程仍在等待accept() ,它表明可能会丢失:

david@debian:~$ valgrind ./server
==24561== Memcheck, a memory error detector
==24561== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==24561== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==24561== Command: ./server
==24561== 
0
1
2
3
4
5
==24561== 
==24561== HEAP SUMMARY:
==24561==     in use at exit: 272 bytes in 1 blocks
==24561==   total heap usage: 3 allocs, 2 frees, 1,408 bytes allocated
==24561== 
==24561== LEAK SUMMARY:
==24561==    definitely lost: 0 bytes in 0 blocks
==24561==    indirectly lost: 0 bytes in 0 blocks
==24561==      possibly lost: 272 bytes in 1 blocks
==24561==    still reachable: 0 bytes in 0 blocks
==24561==         suppressed: 0 bytes in 0 blocks
==24561== Rerun with --leak-check=full to see details of leaked memory
==24561== 
==24561== For counts of detected and suppressed errors, rerun with: -v
==24561== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)

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

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