https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91057

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Author: redi
Date: Wed Oct  9 15:59:56 2019
New Revision: 276762

URL: https://gcc.gnu.org/viewcvs?rev=276762&root=gcc&view=rev
Log:
PR libstdc++/91057 set locale::id::_M_index atomically

If two threads see _M_index==0 concurrently they will both try to set
it, potentially storing the facet at two different indices in the array.

Either set the _M_index data member using an atomic compare-exchange
operation or while holding a mutex.

Also move the LONG_DOUBLE_COMPAT code into a separate function to remove
the visual noise it creates.

        PR libstdc++/91057
        * src/c++98/locale.cc (locale::id::_M_id()) [__GTHREADS]: Use atomic
        compare-exchange or double-checked lock to ensure only one thread sets
        the _M_index variable.
        [_GLIBCXX_LONG_DOUBLE_COMPAT]: Call find_ldbl_sync_facet to detect
        facets that share another facet's ID.
        [_GLIBCXX_LONG_DOUBLE_COMPAT] (find_ldbl_sync_facet): New function.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/src/c++98/locale.cc

Reply via email to