From patchwork Wed Jan 18 17:19:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 716766 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 3v3YcT5vbvz9t22 for ; Thu, 19 Jan 2017 04:19:37 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="nZsSNcLR"; dkim-atps=neutral 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=BB7iea7B1SxSBfn1tysZ0l/LuDpI+t9zi+wnp20uoZjrMrg0BWEoJ pTMbtxhLH3gWK4f41dOCa2NVoKjyrjtakM46S09ljh0a1Uw9+BbfRXX+eD4RfI+J ziJQ9+eGldMHnMOgYXDk0IXbytxJI8tfl2ev8AZSYRK+Sj0EetP1bo= 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=nYEvXAvRH9PclpO9xbZWNxjhDDY=; b=nZsSNcLRPvpgujHUfm8S o0w5KfU+9AZdbSA9YIh3TJRHhmkk2A0CO34LFEAfNRo4DIGfQ42mYKb309m2F4CV ImwuhW19jN2MNlwL5qPO1mBYu1shwJlxFeSKZbKlyp0MP5CKV5vjPz+QlkBmf0hU erRbsqs1yJb0Opp5GtDd6nw= Received: (qmail 79078 invoked by alias); 18 Jan 2017 17:19:16 -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 78992 invoked by uid 89); 18 Jan 2017 17:19:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.1 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=our 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 ESMTP; Wed, 18 Jan 2017 17:19:14 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4F95974E56; Wed, 18 Jan 2017 17:19:14 +0000 (UTC) Received: from localhost (ovpn-116-218.ams2.redhat.com [10.36.116.218]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0IHJD0E020796; Wed, 18 Jan 2017 12:19:13 -0500 Date: Wed, 18 Jan 2017 17:19:11 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR68925 don't use thread_local static for stateless object Message-ID: <20170118171911.GA17685@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.1 (2016-10-04) PR libstdc++/68925 * include/experimental/random (randint): Use temporary instead of thread_local static. Tested powerpc64le-linux, committed to trunk. commit 71544b3d1abd1c9a2d47ef664ce696b750232e0f Author: Jonathan Wakely Date: Wed Jan 18 17:16:10 2017 +0000 PR68925 don't use thread_local static for stateless object PR libstdc++/68925 * include/experimental/random (randint): Use temporary instead of thread_local static. diff --git a/libstdc++-v3/include/experimental/random b/libstdc++-v3/include/experimental/random index 9d5415e..e28df5d 100644 --- a/libstdc++-v3/include/experimental/random +++ b/libstdc++-v3/include/experimental/random @@ -54,8 +54,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static_assert(is_integral<_IntType>::value && sizeof(_IntType) > 1, "argument must be an integer type"); using _Dist = std::uniform_int_distribution<_IntType>; - static thread_local _Dist __dist; - return __dist(_S_randint_engine(), typename _Dist::param_type{__a, __b}); + // This relies on the fact our uniform_int_distribution is stateless, + // otherwise we'd need a static thread_local _Dist and pass it + // _Dist::param_type{__a, __b}. + return _Dist(__a, __b)(_S_randint_engine()); } inline void