From patchwork Thu Oct 26 20:11:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 158678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp142757vqb; Thu, 26 Oct 2023 13:12:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfBr8D3DuXs70RXaHk4YmFvoEf9bepxPMT13I5dght6QJVsHLhCBzQPBv0/FQmNhMc6g+i X-Received: by 2002:a05:622a:2a81:b0:401:e2b1:d28d with SMTP id kf1-20020a05622a2a8100b00401e2b1d28dmr482349qtb.20.1698351165637; Thu, 26 Oct 2023 13:12:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698351165; cv=pass; d=google.com; s=arc-20160816; b=jIuYMpAEkcAURobaL+gl7j4SjbloyOBbCBCJdW5DBRwb613irwpJtEz0Zt1CfHMF43 V+01J3/d3OucVHXKnUHyiJd1FAGX3tQxye/3DwGpQ4+KHA4kem2dElu0+Po9B8GOrUwV 0wA3q4QuZm5RiJIcgXKLsDi/EsiPQgpsJKdc3mtO5pg8w+Cio9dhYoa4SrQOSno4/lit qlooP0fR1eEda1pKP040LcKHqhq9VjY0rKDpgn5ZJUpk4sWybtJ7yxfesbKLy7dFTVh6 Ls9lSuiZxaRwF3CAavfmXhBXcjjOfn2367F3KPO4+UXMHNrzZMrwOoPD3edUPQ9uhAUR Cdxg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=UcIsKCOwcDOfSKjcHEkXvgivG4vC/pJtGSKKRI1k3cE=; fh=sJ+2/4g29YdyXkoRrFZSpsL2zxijepB7X/1rB0LDDh8=; b=Wy+b4JLK5LGQVzdlm65PkbA2Z0W2ZiMOBLnRq0wEwrPWDHzC8M9c8J48zZExR1VxAD NnXxTMWlIH+a/zPZdxt48bYVWidYBnSVponTcsX3Zx2D+u8ta/TZA3fpMd7uKLDjnd6k TG/K5Ec+3lGz3jJmRTUp/U3mVzZPLlAkGJTiZf27eCQHRfPMKlgJDhPxtSNjz9kn2ocM AypRWI1yL4uEbncYTFZMp5kHn4uZEaZ4I4XFuP9/BsrwvfC9B5zxhGwcxQCxHfednrt5 UduTqMKOZou/UdeO7R9R6lbmATk1o823PBZr7wWRKuxAp2IXP7MkPX1iMiu8JlIqeLlI M+aQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Y5UTQ450; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id t22-20020a05622a149600b004198562004csi60806qtx.521.2023.10.26.13.12.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 13:12:45 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Y5UTQ450; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 66ADE3853D02 for ; Thu, 26 Oct 2023 20:12:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 D3659386187C for ; Thu, 26 Oct 2023 20:12:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D3659386187C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D3659386187C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698351142; cv=none; b=tZUD/NgD7snMoIH7bCbuiZXfZRSLsZm/1I+rkR39ph38Hbb+64oyT0STy9wg/gqRsFYLNDO45gFtncZMEsl2mei14HpNbSKUHgNT2bym5lX1IFVjT3+Ls6zk2EtngVAVqo6QkcQBdh8kk23/tKQst6PBGMKe70g5lZuiuXfTYtc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698351142; c=relaxed/simple; bh=w6LR5ds26Tltpxe1qh/3yEWmlbpT7+rNe6O7F7q97PU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ANeEKh2sxan/JqVKL0k76eVfOo73eYrTOdBWuCsbqL1aLBOxIOcuHSyOu4kIizYefFX+DKFNQl/QQQfy4NTRFGuhb3L90XRP8OAI9CTACjU1/xwhKEgRyK2Kn9fq5CDWv6BbqAPt81jhnzG3M3O3Qk97YkrOOTU4Nu1q+/ClzB4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698351140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=UcIsKCOwcDOfSKjcHEkXvgivG4vC/pJtGSKKRI1k3cE=; b=Y5UTQ450b/2HSBPlmVBZskR1cwhq0x/LGrOxVePDyhgEe5SymCj74ssCVGO1Swp5EH8SLA 0jcl8D4RX1I5c+ujCrDZ1rE0eKRanY0KyaawxJnoDEXvqs6cfsdl5p7ATYHrDhNFWK2jDk 7N2waR4cOO6ED3fCeNKFYaRDonjaut4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-426--OvIHiHEN3WMrDNr5Yap8A-1; Thu, 26 Oct 2023 16:12:19 -0400 X-MC-Unique: -OvIHiHEN3WMrDNr5Yap8A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 99F5A1C06904; Thu, 26 Oct 2023 20:12:18 +0000 (UTC) Received: from localhost (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61B3B1121319; Thu, 26 Oct 2023 20:12:18 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix exception thrown by std::shared_lock::unlock() [PR112089] Date: Thu, 26 Oct 2023 21:11:54 +0100 Message-ID: <20231026201217.654112-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, URI_HEX autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780850272155352141 X-GMAIL-MSGID: 1780850272155352141 Tested x86_64-linux. Pushed to trunk. Worth backporting to all active branches, I think. -- >8 -- The incorrect errc constant here looks like a copy&paste error. libstdc++-v3/ChangeLog: PR libstdc++/112089 * include/std/shared_mutex (shared_lock::unlock): Change errc constant to operation_not_permitted. * testsuite/30_threads/shared_lock/locking/112089.cc: New test. --- libstdc++-v3/include/std/shared_mutex | 2 +- .../30_threads/shared_lock/locking/112089.cc | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/30_threads/shared_lock/locking/112089.cc diff --git a/libstdc++-v3/include/std/shared_mutex b/libstdc++-v3/include/std/shared_mutex index 4f236a19806..f205c36533b 100644 --- a/libstdc++-v3/include/std/shared_mutex +++ b/libstdc++-v3/include/std/shared_mutex @@ -820,7 +820,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION unlock() { if (!_M_owns) - __throw_system_error(int(errc::resource_deadlock_would_occur)); + __throw_system_error(int(errc::operation_not_permitted)); _M_pm->unlock_shared(); _M_owns = false; } diff --git a/libstdc++-v3/testsuite/30_threads/shared_lock/locking/112089.cc b/libstdc++-v3/testsuite/30_threads/shared_lock/locking/112089.cc new file mode 100644 index 00000000000..432c17591a1 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/shared_lock/locking/112089.cc @@ -0,0 +1,23 @@ +// { dg-do run { target c++14 } } +// { dg-require-gthreads "" } +// { dg-additional-options "-pthread" { target pthread } } + +#include +#include +#include + +// PR libstdc++/112089 shared_lock::unlock should throw operation_not_permitted + +int main() +{ + std::shared_lock l; + try + { + l.unlock(); + VERIFY( false ); + } + catch (const std::system_error& e) + { + VERIFY( e.code() == std::errc::operation_not_permitted ); + } +}