From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from conssluserg-03.nifty.com (conssluserg-03.nifty.com [210.131.2.82]) by sourceware.org (Postfix) with ESMTPS id E533E3899400 for ; Thu, 13 Jan 2022 11:10:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E533E3899400 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=nifty.ne.jp Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nifty.ne.jp Received: from Express5800-S70 (ae233132.dynamic.ppp.asahi-net.or.jp [14.3.233.132]) (authenticated) by conssluserg-03.nifty.com with ESMTP id 20DB9q6a002627 for ; Thu, 13 Jan 2022 20:09:52 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-03.nifty.com 20DB9q6a002627 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.ne.jp; s=dec2015msa; t=1642072192; bh=oeqwiW5tibe+qDWZJnL0ZJ0+R/BoTTsq86Wl4MECo7A=; h=Date:From:To:Subject:In-Reply-To:References:From; b=fqmYZB+d2Kxf/OgMDPACSHeoSn4quxgV2tMtQwh5wYh90Alo6rE4dKL//VSHQtTFK OWixFXj4pfq+pIBg1M+H/SxIpUKcGJQL28lDsdiaVdE+lQXeAHnEHonm/0IhU7hqmV IxuYQ+KS3krbgx+ECYkcuSj27lOriq2mfeM7yfQc9sLHJ13h5qyYHeZ+2NvoxLTlgq 4ukbQ/cEtiAhvQ//Y2CznbZLJTW0sIQvt84pHgACiByh+gjJTcFBoIc51JSXgizMEb WqlQ+GA3KFXmwf2121h8tx3ak5xNPIAkAzu3ljT9PyvJqE1G5aIakbqyBcqqoWhb4n Jv5X0BYKjJm7g== X-Nifty-SrcIP: [14.3.233.132] Date: Thu, 13 Jan 2022 20:09:52 +0900 From: Takashi Yano To: cygwin-developers@cygwin.com Subject: Re: deadlock on console mutex in gdb Message-Id: <20220113200952.fe8c3b10fe0efda02a68c7e8@nifty.ne.jp> In-Reply-To: References: <20211223054409.610242feb0e96199904b3c9e@nifty.ne.jp> <20211223182440.e37115a4493516aca7ed7873@nifty.ne.jp> <87mtkribfg.fsf@gmail.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: cygwin-developers@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component developers mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Jan 2022 11:10:20 -0000 On Thu, 23 Dec 2021 15:28:58 -0400 David McFarland wrote: > I've also been hitting another console related deadlock, even when > there's no debugger involved: [...] > I can use this program: > > =====test-pt.c > #include > #include > #include > #include > #include > > void *thread(void* p) { > for (int i = 0;; ++i) { > int fd = posix_openpt(O_RDWR | O_NOCTTY); > close(fd); > fprintf(stderr, "test %i\n", i); > } > return 0; > } > > int main() { > pthread_t ids[3]; > for (int i = 0; i < 3; ++i) { > pthread_create(&ids[i], 0, &thread, &ids[i]); > } > for (int i = 0; i < 3; ++i) { > pthread_join(ids[i], 0); > } > return 0; > } > ===== > > compiled with: > > $ gcc -D_GNU_SOURCE test-pt.c -o test-pt > > To hit those asserts. Thanks for the report. I tried your test case, however I encountered another problem of pty. The test case causes memory leak and exhausts the system memory in a short time. I will submit a patch for the memory leak issue. > Perhaps the mutex should never be closed? It's also worrying that > acquiring the mutex just silently fails before a PT is opened. > There could be a thread that is acting as if it has a lock a the time > that the mutex is created, and it will even try to release the lock. > > It might just be safest to create it at process start, but it could have > a significant performance cost. With the patch above, I tried your test case again and confirmed the assertion fails indeed. I also confirmed the deadlock. Thanks for pointing out this. Let me consider. -- Takashi Yano