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 A69113858C00 for ; Mon, 6 Nov 2023 12:17:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A69113858C00 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 A69113858C00 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=1699273076; cv=none; b=A8oXRCH/IDQZxz34kLea9oaIH/mod3hgQpwfS4rFVajA09Vve4vZvH4gun59TqAx42ZfLCjgEXsG2nucCkZ+lickibWn+TE9BL6S220AbyL20+QPutTVSVP3HqgYhCpkJiZkCb+9k0uEwlxv+F3aajr2WC0H6N8KjZthfmBcNrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699273076; c=relaxed/simple; bh=TimjpxvoZOuIN2mgx5oCb2Xt4skZOMSKuikyKBkXs4M=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=O+hgm4xzE/XOcPmqtcbIHSDZclahkYVu72KfgdEJsR3pttB0B9C/BFoRmQQtX6ofutozl4IRJ98eEY3B5tAfP9MXyWox1bhsTydjQxgVTRwxgfElId9Mhzd1VBD6FetGOe119sYL6hBrBeq9wI4dLZYyq354RTECPaKvRhHIRPE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699273075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bkrvV/D3z1OjLfmbY8+GVPoVjajLaCt/MlJfah02vAQ=; b=HLyvOnLOgA++e8j5HA185M6qN3+MsWAMEYOyy3e7e2RCPdBFUEr72N2+YbM4T40naf0BjX hQ0puAwAVxPmESWUINY4zXaPHuQwXNJYvQGtEVN2G9SqWTP9R4gYMjxG4vBREHyn0I0Lh6 AWgfKNwtZkfiKb6lLfVfuCQCtf+Q4Qc= Received: from mail-yw1-f197.google.com (mail-yw1-f197.google.com [209.85.128.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-678-D2N1HFPdNMm7ke6bR0c2cQ-1; Mon, 06 Nov 2023 07:17:54 -0500 X-MC-Unique: D2N1HFPdNMm7ke6bR0c2cQ-1 Received: by mail-yw1-f197.google.com with SMTP id 00721157ae682-5a909b4e079so61313897b3.2 for ; Mon, 06 Nov 2023 04:17:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699273073; x=1699877873; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bkrvV/D3z1OjLfmbY8+GVPoVjajLaCt/MlJfah02vAQ=; b=D+B5ldVHPFZWc22t/SZQ+j6yUK0eziApU8JkEjJvPMHU63qJoIJzT1Y3mGj5xKNZGt 1A8p9fgLVZLFAlKgd50LFMLEnz+ExoMCQbRB8ZVF9rH4Enrm2PwvM3G3WhTGFpMYbx94 /ntJAam+GEKa75X9I9pzrXL/n81OHSavmwquwZ+1A0bBitNBdWwtsSQS2mnHYaAD2Mn2 a+gGjKBQM5643S8R3xV93DMCyEeyzbJLM/p2CVzROpwBZjkw6B25zaLCYdslEE4Dn2BT adRgBqEJ+C14XQDyPs0tTr1SxZ9/TSetM8G6Ku7pc+0cey1UD4FiHmwCqP3xDuqUhXph iJNQ== X-Gm-Message-State: AOJu0YwkrkDqaj9o6d++uTgS8zGqGusmt06JFkoVexgBBLQS/nHG7F4n koTA+jrxlAxmuWE8E8TIKgENs1SfFxMGsDoYf/SDTGZa59mV6mIAivKfYcRytU374ipgQZiALAs mInjFaJJVGsfKuLmlb229G25oikoi7Yw= X-Received: by 2002:a81:4904:0:b0:5b3:2acd:8d83 with SMTP id w4-20020a814904000000b005b32acd8d83mr10896201ywa.22.1699273073747; Mon, 06 Nov 2023 04:17:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5oPYfDTsCQgfwZvZwAZRvBEXx6E2nSBoVOt7QFxi6RFJF5R3EWjvq3OER6PFdoRt9FYhkbT+DqDjV/ijCMkg= X-Received: by 2002:a81:4904:0:b0:5b3:2acd:8d83 with SMTP id w4-20020a814904000000b005b32acd8d83mr10896193ywa.22.1699273073516; Mon, 06 Nov 2023 04:17:53 -0800 (PST) MIME-Version: 1.0 References: <20231106115212.6DCC23858C00@sourceware.org> In-Reply-To: From: Jonathan Wakely Date: Mon, 6 Nov 2023 12:17:42 +0000 Message-ID: Subject: Re: [PATCH] libstdc++/112351 - deal with __gthread_once failure during locale init To: Jakub Jelinek Cc: Richard Biener , gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-12.3 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,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, 6 Nov 2023 at 12:16, Jakub Jelinek wrote: > > On Mon, Nov 06, 2023 at 11:52:08AM +0000, Richard Biener wrote: > > The following makes the C++98 locale init path follow the way the > > C++11 performs initialization. This way we deal with pthread_once > > failing, falling back to non-threadsafe initialization which, given we > > initialize from the library, should be serialized by the dynamic > > loader already. > > > > Bootstrapped and tested on x86_64-unknown-linux-gnu, OK for trunk? > > And GCC 13 branch? > > > > Thanks, > > Richard. > > > > PR libstdc++/112351 > > libstdc++-v3/ > > * src/c++98/locale.cc (locale::facet::_S_get_c_locale): > > Always perform non-threadsafe init when threadsafe init > > failed. > > --- > > libstdc++-v3/src/c++98/locale.cc | 7 ++----- > > 1 file changed, 2 insertions(+), 5 deletions(-) > > > > diff --git a/libstdc++-v3/src/c++98/locale.cc b/libstdc++-v3/src/c++98/locale.cc > > index d308140bab7..e9bec1db3b6 100644 > > --- a/libstdc++-v3/src/c++98/locale.cc > > +++ b/libstdc++-v3/src/c++98/locale.cc > > @@ -216,12 +216,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > #ifdef __GTHREADS > > if (__gthread_active_p()) > > __gthread_once(&_S_once, _S_initialize_once); > > - else > > #endif > > - { > > - if (!_S_c_locale) > > - _S_initialize_once(); > > - } > > + if (__builtin_expect (!_S_c_locale, 0)) > > + _S_initialize_once(); > > return _S_c_locale; > > Wouldn't it be better to just test __gthread_once return value > #ifdef __THREADS > if ((!__gthread_active_p() > || __gthread_once(&_S_once, _S_initialize_once))) > #endif > if (!_S_c_locale) > _S_initialize_once(); > ? This still has the problem of calling the function twice, once because __gthread_once fails and one because it succeeds.