From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 357DC3858418 for ; Wed, 8 Dec 2021 17:27:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 357DC3858418 Received: from mail-yb1-f199.google.com (mail-yb1-f199.google.com [209.85.219.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-568-mB-g-C3gMKmGYbkdPJwOtQ-1; Wed, 08 Dec 2021 12:27:00 -0500 X-MC-Unique: mB-g-C3gMKmGYbkdPJwOtQ-1 Received: by mail-yb1-f199.google.com with SMTP id y125-20020a25dc83000000b005c2326bf744so5464990ybe.21 for ; Wed, 08 Dec 2021 09:27:00 -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=xqCzA7CtpZ2fQfswBXPfWe2qWWAknLPaQa+h0Ngu0GE=; b=mKsAHUHZPGJr4uxgSODCk7Vp2Abobb5nMLpFyQ69uQ2XIBd5gtm2s1n0+oPSicek6P BYvKbKVLfO/8oET9E0xmllHbdZeNnnP6mx+BhDa5MKvQjsq1RwhURsqrirFdbtwMKqI6 Q+OepaS46NL0HYDACHI6uKBmCQP5QVQIMUEXNS8+eKI6YCNE0djGg2AaxI0V54ylrY60 NNqZP3M91rcT6Ft8Cl4H3+VYl/tNhRvnEpiWw4+OqRe1xXmtefaXr4sLPVkvsOCR/jmY BD87bd+vL1cDkReTh9bd+/2rNahbHxBaBSrYYKMtgD/RIowSmBW3t6owKvY5f32+JeLc SoNg== X-Gm-Message-State: AOAM530X9s85FhfX8HY4TT1SIp+6k9vfOZQIHGoirlTx4ycfN/10YKSn YRj3/Jhu4E8HH35I5ff0DTNEskImY2L7vlvjkGYRkmIWvEjK9xlwqnHZFhK3tlOxKaEY6z5si0A j8pFkuFevYbDF5S1nm5nh4otGOpsAlG8= X-Received: by 2002:a05:6902:1107:: with SMTP id o7mr93747ybu.120.1638984419966; Wed, 08 Dec 2021 09:26:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJzy+bTGWoKv5BKVUc/SziOlGaieLBPNxtCcoiOmhShaZhXlH/RATcx6dDEnXx8YxlVo8STOkHdfkIOsm9wH064= X-Received: by 2002:a05:6902:1107:: with SMTP id o7mr93725ybu.120.1638984419714; Wed, 08 Dec 2021 09:26:59 -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: Jonathan Wakely Date: Wed, 8 Dec 2021 17:26:48 +0000 Message-ID: Subject: Re: [PATCH] libstdc++: Allow std::condition_variable waits to be cancelled [PR103382] To: Jonathan Wakely Cc: Florian Weimer , "Jonathan Wakely via Libstdc++" , gcc-patches X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="000000000000218b2605d2a5ccdf" X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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:27:04 -0000 --000000000000218b2605d2a5ccdf Content-Type: text/plain; charset="UTF-8" On Wed, 8 Dec 2021 at 00:36, Jonathan Wakely wrote: > > On Tue, 7 Dec 2021 at 21:52, Florian Weimer wrote: > > > > * Jonathan Wakely: > > > > > On Tue, 7 Dec 2021, 21:20 Florian Weimer via Libstdc++, > > > wrote: > > > > > > * Jonathan Wakely via Libstdc: > > > > > > > If necessary we could keep the terminate-on-cancellation behaviour as > > > > _ZNSt18condition_variable4waitERSt11unique_lockISt5mutexE@GLIBCXX_3.4.11 > > > > and export the new behaviour as @@GLIBCXX_3.4.30, although this patch > > > > doesn't do that. > > > > > > Note that if this fix escapes into the wild and then you have to make > > > the symbol version change, you will break newer applications. In a few > > > cases in glibc, we proactively added aliases at a different symbol > > > version, but with the same implementation (at first). > > > > > > To be safe, we probably should preserve the old behaviour for the old > > > version of the symbol. If we decide that the new behaviour is always > > > preferable, we could change that later by making the old symbol an > > > alias for the new. If we don't decide that, we'll be glad we made it a > > > separate symbol. > > > > On the other hand, with separate versions, it's possible to reintroduce > > the old behavior at a later date, as a bugfix. It's not strictly > > necessary to do that work upfront. It's just nice to have this option. > > Ah yes, a new symbol version gives us more flexibility in every direction. > > > > I'll see if I can get it working with two versioned symbols. We don't > > > actually do that in libstdc++ currently, we only have a single version > > > of every symbol. > > > > Ping me if you want to discuss options. 8-> > > Thanks. I'll try it and let you know how I get on. 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. --000000000000218b2605d2a5ccdf Content-Type: text/plain; charset="US-ASCII"; name="patch.txt" Content-Disposition: attachment; filename="patch.txt" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_kwxszesy0 ZGlmZiAtLWdpdCBhL2xpYnN0ZGMrKy12My9jb25maWcvYWJpL3ByZS9nbnUudmVyIGIvbGlic3Rk YysrLXYzL2NvbmZpZy9hYmkvcHJlL2dudS52ZXIKaW5kZXggOGYzYzdiMzgyN2UuLmI3NDczNTFh MWI5IDEwMDY0NAotLS0gYS9saWJzdGRjKystdjMvY29uZmlnL2FiaS9wcmUvZ251LnZlcgorKysg Yi9saWJzdGRjKystdjMvY29uZmlnL2FiaS9wcmUvZ251LnZlcgpAQCAtMTI4NSw3ICsxMjg1LDYg QEAgR0xJQkNYWF8zLjQuMTEgewogICAgICMgY29uZGl0aW9uX3ZhcmlhYmxlCiAgICAgX1pOU3Qx OGNvbmRpdGlvbl92YXJpYWJsZTEwbm90aWZ5X2FsbEV2OwogICAgIF9aTlN0MThjb25kaXRpb25f dmFyaWFibGUxMG5vdGlmeV9vbmVFdjsKLSAgICBfWk5TdDE4Y29uZGl0aW9uX3ZhcmlhYmxlNHdh aXRFUlN0MTF1bmlxdWVfbG9ja0lTdDVtdXRleEU7CiAgICAgX1pOU3QxOGNvbmRpdGlvbl92YXJp YWJsZUMxRXY7CiAgICAgX1pOU3QxOGNvbmRpdGlvbl92YXJpYWJsZUMyRXY7CiAgICAgX1pOU3Qx OGNvbmRpdGlvbl92YXJpYWJsZUQxRXY7CkBAIC0xMjk1LDYgKzEyOTQsMTIgQEAgR0xJQkNYWF8z LjQuMTEgewogICAgIF9aTlN0MjJjb25kaXRpb25fdmFyaWFibGVfYW55RDFFdjsKICAgICBfWk5T dDIyY29uZGl0aW9uX3ZhcmlhYmxlX2FueUQyRXY7CiAKKyNpZm5kZWYgSEFWRV9TWU1WRVJfU1lN Qk9MX1JFTkFNSU5HX1JVTlRJTUVfU1VQUE9SVAorICAgICMgVGhlIG9yaWdpbmFsIGRlZm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