From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id eEYAHrQu12CgUgAAWB0awg (envelope-from ) for ; Sat, 26 Jun 2021 09:42:12 -0400 Received: by simark.ca (Postfix, from userid 112) id 6B26C1F1F2; Sat, 26 Jun 2021 09:42:12 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=MAILING_LIST_MULTI, RDNS_DYNAMIC autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A789B1E54D for ; Sat, 26 Jun 2021 09:42:11 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 01D20383D806 for ; Sat, 26 Jun 2021 13:42:11 +0000 (GMT) Received: from mx2.freebsd.org (mx2.freebsd.org [IPv6:2610:1c1:1:606c::19:2]) by sourceware.org (Postfix) with ESMTPS id 6E9E63857419 for ; Sat, 26 Jun 2021 13:41:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6E9E63857419 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "R3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id A8137809AF; Sat, 26 Jun 2021 13:41:55 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GBw5b481Xz4lm0; Sat, 26 Jun 2021 13:41:55 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from John-Baldwins-MacBook-Pro.local (d-24-233-223-154.va.cpe.atlanticbb.net [24.233.223.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 60F1522580; Sat, 26 Jun 2021 13:41:55 +0000 (UTC) (envelope-from jhb@FreeBSD.org) To: Simon Marchi , Pedro Alves , gdb-patches@sourceware.org References: <20210615111429.1879286-1-pedro@palves.net> <20210615111429.1879286-4-pedro@palves.net> From: John Baldwin Subject: Re: [PATCH 3/4] scoped_ignore_signal: Use sigprocmask+sigtimedwait instead of signal Message-ID: <6dca033a-1b6f-05df-8dd0-e1cc2c7d85d2@FreeBSD.org> Date: Sat, 26 Jun 2021 09:41:55 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 6/26/21 5:35 AM, Simon Marchi via Gdb-patches wrote: > On 2021-06-15 7:14 a.m., Pedro Alves wrote: >> The problem with using signal(...) to temporarily ignore a signal, is >> that that changes the the signal disposition for the whole process. >> If multiple threads do it at the same time, you have a race. >> >> Fix this by using sigprocmask + sigtimedwait to implement the ignoring >> instead, if available, which I think probably means everywhere except >> Windows nowadays. This way, we only change the signal mask for the >> current thread, so there's no race. > > I tried to build on macOS today and got: > > > CXX compile/compile.o > In file included from /Users/smarchi/src/binutils-gdb/gdb/compile/compile.c:46: > /Users/smarchi/src/binutils-gdb/gdb/../gdbsupport/scoped_ignore_signal.h:69:4: error: use of undeclared identifier 'sigtimedwait' > sigtimedwait (&set, nullptr, &zero_timeout); > ^ > > I didn't have time to dig yet. It looks like macOS doesn't implement either sigtimedwait() or sigwaitinfo() which are part of POSIX from 1996 (*sigh*); however, macOS does provide sigpending() and sigwait(), so perhaps we can do something like: if (ConsumePending) { #ifdef HAVE_SIGTIMEDWAIT const timespec zero_timeout = {}; sigtimedwait (&set, nullptr, &zero_timeout); #else sigset_t pending; sigpending (&pending); if (sigismember (&pending, SIG)) sigwait (&set, nullptr); #endif } (Ironically, sigwait() was added to POSIX in the same version of the spec as sigtimedwait().) -- John Baldwin