From patchwork Mon Sep 22 14:54:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 391997 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 492B314011D for ; Tue, 23 Sep 2014 00:54:49 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=IK0JN8vUkckRHHqMucxqO5mOr1sGDL8XiT6XIu0cHHE/0WJ1BwDyN zI0hqfr1kr5DVJatk8EbY3O3+1zbB85RoVilBuODbdHo0EOMV/FciTvg62aCpGwy EyERifjX2EecUu5lcFttpQtXKYvw4HMaNe4XmtJC18KZvhT7+7TIQA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=9QO+wnj1zc3C9Bs2XQssoVXSj9E=; b=ONZk5LHPvYBEBj77r/P/ Fl4EswMPxeZ4ot4fzJG5M/Vnx78CmP3yK4hwWy/N1UzR4GI8Lh7uJC8a96tN2bHx eesAaJa+0X33TUIZyyiZ85q2+J7Qrzbvne0EoWKwpG3VOND8pe+qt65KhDVKZ7MS +Qwr5XHmSXDp6ZpHo+K1w7s= Received: (qmail 5556 invoked by alias); 22 Sep 2014 14:54:40 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 5348 invoked by uid 89); 22 Sep 2014 14:54:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 22 Sep 2014 14:54:37 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8MEsa0C002313 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 22 Sep 2014 10:54:36 -0400 Received: from localhost (ovpn-116-40.ams2.redhat.com [10.36.116.40]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8MEsZCC025572; Mon, 22 Sep 2014 10:54:35 -0400 Date: Mon, 22 Sep 2014 15:54:35 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [patch] Fix std::try_lock behaviour Message-ID: <20140922145434.GB2669@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) When I fixed std::try_lock a few years ago I misread the spec, exceptions should not be caught and turned into a return value. Tested x86_64-linux, committed to trunk. commit 5effca670aa009c60e31b639604da4d00f388038 Author: Jonathan Wakely Date: Thu Sep 18 16:15:54 2014 +0100 * include/std/mutex (try_lock): Do not swallow exceptions. * testsuite/30_threads/try_lock/4.cc: Fix test. diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex index f6b851c..d80fa5a 100644 --- a/libstdc++-v3/include/std/mutex +++ b/libstdc++-v3/include/std/mutex @@ -630,12 +630,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { int __idx; auto __locks = std::tie(__l1, __l2, __l3...); - __try - { __try_lock_impl<0>::__do_try_lock(__locks, __idx); } - __catch(const __cxxabiv1::__forced_unwind&) - { __throw_exception_again; } - __catch(...) - { } + __try_lock_impl<0>::__do_try_lock(__locks, __idx); return __idx; } diff --git a/libstdc++-v3/testsuite/30_threads/try_lock/4.cc b/libstdc++-v3/testsuite/30_threads/try_lock/4.cc index 7741798..1212b65 100644 --- a/libstdc++-v3/testsuite/30_threads/try_lock/4.cc +++ b/libstdc++-v3/testsuite/30_threads/try_lock/4.cc @@ -133,8 +133,15 @@ void test03() while (unreliable_lock::throw_on < 3) { unreliable_lock::count = 0; - int failed = std::try_lock(l1, l2, l3); - VERIFY( failed == unreliable_lock::throw_on ); + try + { + std::try_lock(l1, l2, l3); + VERIFY( false ); + } + catch (int e) + { + VERIFY( e == unreliable_lock::throw_on ); + } ++unreliable_lock::throw_on; } }