From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5557 invoked by alias); 18 Mar 2004 15:29:02 -0000 Mailing-List: contact pthreads-win32-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sources.redhat.com Received: (qmail 5536 invoked from network); 18 Mar 2004 15:28:59 -0000 Received: from unknown (HELO smtpcl1.fiducia.de) (195.200.32.50) by sources.redhat.com with SMTP; 18 Mar 2004 15:28:59 -0000 Received: from xcsmtp01.fiducia.de (xcsmtp01.fiducia.de [10.253.17.9]) by smtpcl1.fiducia.de with ESMTP id i2IFSvb28730 for ; Thu, 18 Mar 2004 16:28:57 +0100 (MET) Sensitivity: Subject: Memory leak using detaching over Thread-Attributes with example To: pthreads-win32@sources.redhat.com From: Rainer.Schiele@fiducia.de Date: Thu, 18 Mar 2004 15:29:00 -0000 Message-ID: MIME-Version: 1.0 Content-type: text/plain; charset=us-ascii X-SW-Source: 2004/txt/msg00035.txt.bz2 Hello, I'm encounter an problem that an memory leak occur (and also the Windows Handles run out), when I detach an Thread with the Thread-Attributes on pthread_create using pthread_attr_init and pthread_setdetachstate. Using another approach creating an Thread with pthread_create (attr == NULL) and calls then pthread_detach on the Thread-ID no leak occur. I'm using Windows XP, MinGW-3.1.0-1, MSYS-1.0.9. Looking in the code i found nothing special. Any Hints? Thanks Rainer #include #include #include void *ThreadFunc(void *ptr); int main(int argc, char *argv[]) { pthread_t tid; pthread_attr_t attr; int rc, i; int detachstate; /* rc = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (rc != 0) { fprintf(stderr,"pthread_attr_setdetachstate rc=%d\n", rc); return 1; } */ /* detachstate = 1; rc = pthread_attr_setdetachstate(&attr, detachstate); if (rc != 0) { fprintf(stderr,"pthread_attr_setdetachstate rc=%d\n", rc); return 1; } */ fprintf(stderr,"Threadtest started\n"); for(i=0; i<10 ;i++) { /*rc = pthread_create(&tid, &attr, ThreadFunc, (void*) i);*/ Sleep(5000); rc = pthread_create(&tid, NULL, ThreadFunc, (void*) i); if (rc != 0) { fprintf(stderr,"pthread_create(%d) rc=%d\n", i, rc); return 1; } rc = pthread_detach(tid); if (rc != 0) { fprintf(stderr,"pthread_detach(%d) rc=%d\n", i, rc); return 1; } } fprintf(stderr,"Threadtest ended\n"); Sleep(100000); } void *ThreadFunc(void *ptr) { int j = (int) ptr; fprintf(stderr,"Thread %d started\n", j); Sleep(10000); fprintf(stderr,"Thread %d ended\n", j); return (NULL); }