From owner-freebsd-stable@FreeBSD.ORG Thu Apr 24 09:30:28 2008 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2B4EE1065674 for ; Thu, 24 Apr 2008 09:30:28 +0000 (UTC) (envelope-from krassi@bulinfo.net) Received: from mx.bulinfo.net (mx.bulinfo.net [193.194.156.1]) by mx1.freebsd.org (Postfix) with ESMTP id 0614D8FC18 for ; Thu, 24 Apr 2008 09:30:27 +0000 (UTC) (envelope-from krassi@bulinfo.net) Received: from localhost (localhost [127.0.0.1]) by mx.bulinfo.net (Postfix) with ESMTP id 9CF372D8C6 for ; Thu, 24 Apr 2008 12:04:24 +0300 (EEST) Received: from mx.bulinfo.net ([127.0.0.1]) by localhost (mx.bulinfo.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 04786-09 for ; Thu, 24 Apr 2008 12:04:21 +0300 (EEST) Received: from [192.168.2.188] (pythia.bulinfo.net [212.72.195.5]) by mx.bulinfo.net (Postfix) with ESMTP id CF7B82D8A4 for ; Thu, 24 Apr 2008 12:04:21 +0300 (EEST) Message-ID: <48104D14.8000400@bulinfo.net> Date: Thu, 24 Apr 2008 12:04:20 +0300 From: Krassimir Slavchev User-Agent: Thunderbird 2.0.0.9 (X11/20071122) MIME-Version: 1.0 To: FreeBSD X-Enigmail-Version: 0.95.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: amavisd-new at mx.bulinfo.net Subject: threads cleanup? X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Apr 2008 09:30:28 -0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, Most probably I missed something. I have problems with threads cleanup. Here are output of valgrind and simple test program: ... ==78317== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) ==78317== malloc/free: in use at exit: 4108 bytes in 2 blocks. ==78317== malloc/free: 5 allocs, 3 frees, 4324 bytes allocated. ==78317== ==78317== searching for pointers to 2 not-freed blocks. ==78317== checked 1468040 bytes. ==78317== ==78317== 12 bytes in 1 blocks are still reachable in loss record 1 of 2 ==78317== at 0x3C038183: malloc (in /usr/local/lib/valgrind/vgpreload_memcheck.so) ==78317== by 0x3C03F8D0: (within /usr/local/lib/valgrind/libthr.so.2) ==78317== by 0x3C040F49: pthread_mutex_init (in /usr/local/lib/valgrind/libthr.so.2) ==78317== by 0x3C040FA9: pthread_mutex_lock (in /usr/local/lib/valgrind/libthr.so.2) ==78317== ==78317== ==78317== 4096 bytes in 1 blocks are still reachable in loss record 2 of 2 ==78317== at 0x3C038183: malloc (in /usr/local/lib/valgrind/vgpreload_memcheck.so) ==78317== by 0x3C121AE5: __smakebuf (in /lib/libc.so.6) ==78317== by 0x3C1219B0: __swsetup (in /lib/libc.so.6) ==78317== by 0x3C11789B: __vfprintf (in /lib/libc.so.6) ... #include #include void *Worker(void * flags) { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); printf("Worker started!\n"); sleep(1); printf("Worker finiched!\n"); *(int *)flags = 1; for(;;) { printf("pthread_testcancel()!\n"); pthread_testcancel(); sleep(1); } } int main() { pthread_t tid, tid2; void * arg; arg = (int *)malloc(sizeof(int)); *(int *)arg = 0; pthread_create(&tid, NULL, Worker, arg); for(;;) { if(*(int *)arg) { printf("pthread_cancel()!\n"); pthread_cancel(tid); free(arg); pthread_exit((void *)0); } sleep(1); } } Any hints? Best Regards -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (FreeBSD) iD8DBQFIEE0UxJBWvpalMpkRAjluAKCpkMLNnK5+/Wwz0jAmdnqi6O1zyACeNf1F kJHy5JX5fLb3rLFwq/Mis74= =oBmp -----END PGP SIGNATURE-----