[libcxx-commits] [libcxx] [libc++] Speed up classic locale (PR #72112)
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Nov 16 06:53:57 PST 2023
================
@@ -538,16 +543,31 @@ locale::__imp::use_facet(long id) const
// locale
+std::atomic<locale::__imp*> locale::__imp::classic_;
+
const locale&
locale::__imp::make_classic()
{
// only one thread can get in here and it only gets in once
alignas(locale) static std::byte buf[sizeof(locale)];
locale* c = reinterpret_cast<locale*>(&buf);
c->__locale_ = &make<__imp>(1u);
+ classic_.store(c->__locale_, std::memory_order_relaxed);
----------------
mordante wrote:
I agree we only care about the value of the pointer and not what information deferring the pointer gives. I agree this should happen
```
// If a locale uses the classic imp, then this store happens
// before acquire/release methods, and they must observe the
// right value and omit reference counting.
```
However I don't see any guarantee this does happen. Per https://en.cppreference.com/w/cpp/atomic/memory_order
```
Relaxed operation: there are no synchronization or ordering constraints imposed on other reads or writes, only this operation's atomicity is guaranteed (see [Relaxed ordering](https://en.cppreference.com/w/cpp/atomic/memory_order#Relaxed_ordering) below).
```
Specifically I see no guarantee that when Thread A creates the classic locale and thread B uses it the classic locale the value of `classic_` read in Thread B is the value stored in Thread A. Can you explain what I'm missing?
https://github.com/llvm/llvm-project/pull/72112
More information about the libcxx-commits
mailing list