From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24095 invoked by alias); 4 Mar 2005 17:06:38 -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 23976 invoked from network); 4 Mar 2005 17:06:24 -0000 Received: from unknown (HELO rproxy.gmail.com) (64.233.170.201) by sourceware.org with SMTP; 4 Mar 2005 17:06:24 -0000 Received: by rproxy.gmail.com with SMTP id c51so605640rne for ; Fri, 04 Mar 2005 09:06:23 -0800 (PST) Received: by 10.38.126.55 with SMTP id y55mr17358rnc; Fri, 04 Mar 2005 09:05:35 -0800 (PST) Received: by 10.54.7.8 with HTTP; Fri, 4 Mar 2005 09:03:59 -0800 (PST) Message-ID: <97ffb310503040903186c281e@mail.gmail.com> Date: Fri, 04 Mar 2005 17:06:00 -0000 From: Gottlob Frege Reply-To: Gottlob Frege To: Dmitry Sernii Subject: Re: Handle leak when using pthread mutex with win32 api threads Cc: pthreads-win32@sources.redhat.com In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: X-SW-Source: 2005/txt/msg00019.txt.bz2 On Fri, 4 Mar 2005 17:52:58 +0200, Dmitry Sernii wrote: > Hello All! > I have handle leak, when using win32 api threads with pthread mutexes. > I'm using pthread-win32 2005-01-03 pthread snapshot. > > Here is the sample application which reproduce the problem: > > #include > #include > #include > > const int max_threads = 500; > > DWORD WINAPI threadProc(void* param) > { > static pthread_mutex_t mutex(PTHREAD_RECURSIVE_MUTEX_INITIALIZER); that line above is not thread safe. you might initialize the same mutex multiple times. Not good. > pthread_mutex_lock(&mutex); > pthread_mutex_unlock(&mutex); > return 0; > } > > void main() > { > DWORD id; > HANDLE th[max_threads]; > int i; > for (i=0;i th[i]=CreateThread(0,0,threadProc,0,0,&id); > > for (i=0;i { > WaitForSingleObject(th[i],INFINITE); > CloseHandle(th[i]); > } > getch(); > } > > after that if you take a look at Task Manager you can see lots of > handlers used by the program. If you replace win32 API threads with > pthreads everything works fine. Also this program works ok if you > change pthread mutexes with win32 mutexes. > The same problem happends when using QT threads (version 3.3.4 > )instead of win32 api threads. > > problem reproduces with MSVC 6.0 compiler. > > Best Regards, > Dmitrii Sernii >