From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by sourceware.org (Postfix) with ESMTPS id 80C933858413; Wed, 8 Dec 2021 17:36:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 80C933858413 Received: by mail-yb1-xb34.google.com with SMTP id j2so7630792ybg.9; Wed, 08 Dec 2021 09:36:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=08c+lUsP3/V4VjiFHizp2gytMf/lLZJB5j6Cwa3/vP4=; b=lodw8pwBPOuY9KuwrW0hu2L826ds9/eEWWiY1QSdx79dPMWgbR3qEE6gd24VJIxfNq A0zrW+7OELOtkg+8/fWvRe0n7tFUe2IQad9oPiFtwJzhFFUibi8I/ecnvcgmTb8W3u8O DLPkCmfUqRSfCs9q8K2ATT/rf7hjM2YR/dkd8yHAHN+2TMbcfB775rti+kgbGO599yXP 7eRlCRNnz9IOdpCRDrN5RJBRYZJFO+sQJKR3aWwRiiy88S7En6rgw11u52cZKKCrLA3W uCStaihD0zKc0vL2QlKMz1Rqm+b7UtByc5jhrjNf474DtpWtlRAmIc/kwQAH6Qf8vLmY LqnA== X-Gm-Message-State: AOAM532mZ0+TTcrBdbylo9fQ4yh1Jm7yo7KFU4V+vWcqbkl2dJAtyLGE kN2IjfdmjIi6XmX++MANYgs+lQGIoxOA4bCVDI0= X-Google-Smtp-Source: ABdhPJyjrVcCrJxuq/z8djpkAhFimjnhm9GeOu9W0F8EpYhlRJdAQILvJwAfp/qGVG2kI6QDTeUmRIoCDI1Zyg7k/1s= X-Received: by 2002:a25:cf44:: with SMTP id f65mr73366ybg.257.1638984984076; Wed, 08 Dec 2021 09:36:24 -0800 (PST) MIME-Version: 1.0 References: <20211207205803.1142706-1-jwakely@redhat.com> <871r2onmfg.fsf@oldenburg.str.redhat.com> <87tufkm6bb.fsf@oldenburg.str.redhat.com> In-Reply-To: From: Ville Voutilainen Date: Wed, 8 Dec 2021 19:36:13 +0200 Message-ID: Subject: Re: [PATCH] libstdc++: Allow std::condition_variable waits to be cancelled [PR103382] To: Jonathan Wakely Cc: Jonathan Wakely , Florian Weimer , "Jonathan Wakely via Libstdc++" , gcc-patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Dec 2021 17:36:25 -0000 On Wed, 8 Dec 2021 at 19:27, Jonathan Wakely via Libstdc++ wrote: > After resolving a PEBKAC issue, here's an incremental diff that > preserves the old behaviour for the existing @GLIBCXX_3.4.11 symbol, > but adds a new @@GLIBCXX_3.4.30 symbol that supports cancellation via > __forced_unwind. > > Maybe we should also do this in the implementation of the old noexcept function: > > __attribute__((used)) > void > __nothrow_wait_cv::wait(std::unique_lock& lock) noexcept > { > int old; > int err = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old); > this->condition_variable::wait(lock); > if (!err && old != PTHREAD_CANCEL_DISABLE) > pthread_setcancelstate(old, &old); > } > > This would prevent cancellation from terminating a process if it uses > the old symbol. So we'd have a new symbol that supports cancellation, > and an old one that safely disables it. That sounds good to me. Also, I'm not sure it was pointed out, for the original: changing a noexcept function to start throwing can leak exceptions through other noexcept functions, hitting catch-blocks instead of terminates, or terminates that occur much later than intended. The compiler will assume that it doesn't need to set up the LSDA in a noexcept function if everything you call is noexcept, and then you don't have the LSDA that would terminate right then and there. That's probably a lesser problem for the thread cancellation exception than it would be for some others, but it's a blood-curdling/chilling possibility that we should just avoid. And you have done that, thanks for that.