1
더 많은 일반적인 쿼리인데, 생성 된 스레드 중 일부가 정상적으로 종료되지 않는 경우 valgrind memcheck의 동작이 무엇입니까? 스레드가 분리되어 부모 프로세스/스레드와 메모리를 공유하지 않는 경우를 의미합니다.모든 스레드가 종료되지 않을 때의 Valgrind 출력
는이 코드 조각 그냥 호기심
더 많은 일반적인 쿼리인데, 생성 된 스레드 중 일부가 정상적으로 종료되지 않는 경우 valgrind memcheck의 동작이 무엇입니까? 스레드가 분리되어 부모 프로세스/스레드와 메모리를 공유하지 않는 경우를 의미합니다.모든 스레드가 종료되지 않을 때의 Valgrind 출력
는이 코드 조각 그냥 호기심
중 질문이기 때문에 내가 어떤 코드 또는 Valgrind의 출력을 해달라고 :
스레드가 여전히accept()
을 기다리고
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);
, 그것은 아마도 잃어버린 것을 보여줍니다 :
[email protected]:~$ 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)
프로세스가 종료에 실패하지 않으면 걱정하지 마십시오. –
이 경우 pthread_create()에 의해 생성 된 스레드는 무엇입니까? , 프로세스의 과정에서 자체 메모리를 얻게되고 분리 된 스레드이므로 부모가 다운되면 할당되지 않습니다. – samairtimer
메인 스레드는 자식을 기다리지 않고 열려있는 모든 스레드가 중단되므로 가능한 메모리 누수가 생기고 뮤텍스를 사용하여 스레드를 sinchronize합니다. –