public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Richard Biener <rguenther@suse.de>,
	gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: [PATCH] libstdc++/112351 - deal with __gthread_once failure during locale init
Date: Mon, 6 Nov 2023 12:17:42 +0000	[thread overview]
Message-ID: <CACb0b4kmiCpgZGBTPsNx_smex0zQ7P-iMKdXJg3yCBSELWcKiA@mail.gmail.com> (raw)
In-Reply-To: <ZUjZDPP127sty410@tucnak>

On Mon, 6 Nov 2023 at 12:16, Jakub Jelinek <jakub@redhat.com> 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.


  reply	other threads:[~2023-11-06 12:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20231106115212.6DCC23858C00@sourceware.org>
2023-11-06 12:16 ` Jakub Jelinek
2023-11-06 12:17   ` Jonathan Wakely [this message]
     [not found] <11125.123110606520900751@us-mta-255.us.mimecast.lan>
2023-11-06 12:15 ` Jonathan Wakely
2023-11-06 12:51   ` Richard Biener
2023-11-07 10:55     ` Richard Biener
2023-11-07 11:44     ` Jonathan Wakely
2023-11-06 11:52 Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACb0b4kmiCpgZGBTPsNx_smex0zQ7P-iMKdXJg3yCBSELWcKiA@mail.gmail.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=libstdc++@gcc.gnu.org \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).