From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta002.cacentral1.a.cloudfilter.net (omta002.cacentral1.a.cloudfilter.net [3.97.99.33]) by sourceware.org (Postfix) with ESMTPS id 9DAD73858D20 for ; Tue, 23 Jan 2024 03:24:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9DAD73858D20 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=kylheku.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=shaw.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9DAD73858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=3.97.99.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705980298; cv=none; b=MDnrU19u/Uie6iW2FpAtu6SyRWUdM7ZeiknbLVZYBm83Hg641rDgvtu4GuExZJ0mJO3pnvt+TZNO9jdqe3M39ZfaaFyPzQXjlfkL2vammMHtCHs4GungU40aWhTO0Tcx29d3PSCkDf86iwkGwLzZbOTAbbcnGfZiqRKRs6DS3j0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705980298; c=relaxed/simple; bh=XUkapy+3tdNcNGGhnCRLFHIzzB8nRsSpXormm0AM4tg=; h=DKIM-Signature:MIME-Version:Date:From:To:Subject:Message-ID; b=bu6b4eBS8RIxadrsxe8V9N/RqfBUEoAG+ADruwFqgTxMvis314JIGfAYlboLuk3vwYLHNBXE/wcRN9KvzZp1cDYI0oIqo+HmabV6CirX9a4gCtTyxoUPswNPmSEF1Ni0chOi9poMCwdGB5dFdUtZT3kEcvlNxxjqqhyMbG722II= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from shw-obgw-4004a.ext.cloudfilter.net ([10.228.9.227]) by cmsmtp with ESMTPS id RzaxrxBTdGAIJS7PErrsOk; Tue, 23 Jan 2024 03:24:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=shaw.ca; s=s20180605; t=1705980296; bh=XUkapy+3tdNcNGGhnCRLFHIzzB8nRsSpXormm0AM4tg=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=fVPc+WYGvWY8qOKRMcNMYb3rxFMXgV+9qVXQdZz9PI/CM4p3NFVnoQGXnKue+kytO oT1XDkFzW1cJtA1QpnvO7qTu3b4QQa9ls0K7GNm2BMkqJ5GHznOxiiMJbwR6xci4zG hHQHrtF38Wn4mDeK/o/bZODERHMt+2GAl1Vs1n8ph94QYB/ayZZMG8A4qYduV7+Wp8 Viqh2DUMVgPvYgOnNhrv5WdNsZOLThLRrEZuYe2zvLjXGbDJnKOQImQ9H+u0JZj8ck xmvmwUy3fs63GhNjlo2LBU3/TxQ3c2RkdiCpXufXBVyYd8dPOr2OL0Vc1ypwb4t//w 0KzdKpwihvgTw== Received: from kylheku.com ([70.79.182.7]) by cmsmtp with ESMTPSA id S7PCryzzjWIKPS7PDrPvsJ; Tue, 23 Jan 2024 03:24:56 +0000 Authentication-Results: ; auth=pass (PLAIN) smtp.auth=kkylheku@shaw.ca X-Authority-Analysis: v=2.4 cv=D+pUl9dj c=1 sm=1 tr=0 ts=65af3188 a=pMSlDXUwMa7SJ1EIez8PdQ==:117 a=pMSlDXUwMa7SJ1EIez8PdQ==:17 a=xqWC_Br6kY4A:10 a=kj9zAlcOel0A:10 a=dEuoMetlWLkA:10 a=uZvujYp8AAAA:8 a=S1gdvm2_QrogmFSBmPsA:9 a=CjuIK1q_8ugA:10 a=h0-zxJNUdx4A:10 a=SLzB8X_8jTLwj6mN0q5r:22 Received: from localhost ([::1] helo=mail.kylheku.com) by kylheku.com with esmtp (Exim 4.94.2) (envelope-from ) id 1rS7PB-00CNky-3c; Mon, 22 Jan 2024 19:24:53 -0800 MIME-Version: 1.0 Date: Mon, 22 Jan 2024 19:24:52 -0800 From: Kaz Kylheku To: Takashi Yano Cc: cygwin@cygwin.com Subject: Re: Possiblly bug of cygwin1.dll In-Reply-To: <20240120131825.4157c259fe058155137d6fe0@nifty.ne.jp> References: <20240119224436.876a055f356f7c6796bc725b@nifty.ne.jp> <20240120131825.4157c259fe058155137d6fe0@nifty.ne.jp> User-Agent: Roundcube Webmail/1.4.15 Message-ID: X-Sender: kaz@kylheku.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4xfMrQ7HdKxIYE076bjNcSDatf6wAa68+gKviroRyNfE3HB0TxOG+c/ikW3qT4P/tozc7IApi6tQjFpzVKNaJh8x4VukMI9fqqiwiW1tRgvdHSvPatb+d5 CSjcUfkgdvEMIA4PFf+NEXmhkods6bjz4dKkcfgvvQg+mvAJgpzTS0Ayca9duwTmicVWLhrUukd+csLnXmHgDFyIDiGYbdGNIWI= X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2024-01-19 20:18, Takashi Yano via Cygwin wrote: > And I tried to observe the pthread_mutex_xxx() call. Then found the > test case does like: > > #include > int main() > { > for (;;) { > pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; > pthread_mutex_lock(&m); > pthread_mutex_unlock(&m); > } > return 0; > } Note POSIX: In cases where default mutex attributes are appropriate, the macro PTHREAD_MUTEX_INITIALIZER can be used to initialize mutexes. The effect shall be equivalent to dynamic initialization by a call to pthread_mutex_init() with parameter attr specified as NULL, except that no error checks are performed. Thus, the following is correct: for (;;) { pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&m); pthread_mutex_unlock(&m); pthread_mutex_destroy(&m); // <--- added } Does your above code leak if you add the destroy call? If so, pthread_mutex_destroy needs to be fixed. Either way, libstdc++ should be calling pthread_mutex_destroy in the destructor, in spite of initializing the object with a simple initializer. That libstdc++ library could be fixed in the same way; the mutex object's destructor should call pthread_mutex_destroy, even though the constructor didn't call pthread_mutex_init. This is a "moral equivalent": class buf { unsigned char *ptr; public: buf() : ptr(NULL) { } ~buf() { delete [] ptr; } // ... }; Just because you have a constructor that trivially initializes some resource with a constant expression doesn't mean that the destructor has nothing to free. In between there the object is mutated so that it holds resources. > POSIX states pthread_mutex_t can be initialized with > PTREAD_MUTEX_INITIALZER when it is STATICALLY allocated. I'm looking at this and don't see such a constraint: https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_destroy.html The word "static" only occurs in the Rationale section. Use of the initializer is not restricted to static objects by any normative wording. In real systems, the static distinction has no meaning. This code can be inside a shared library: static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; this library could be loaded by dlopen and unloaded with dlclose. Thus static becomes dynamic! And, by the way, this is a problem: if we have a library which does the above, and we repeatedly load it and unload it while using the mutex in between, it will leak. I think you don't want to do this kind of initialization in reloadable plugins, unless you put in some destructor hooks, or wrap it with C++ objects with destructors.