https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> --- This should do it: --- a/libstdc++-v3/src/c++17/memory_resource.cc +++ b/libstdc++-v3/src/c++17/memory_resource.cc @@ -25,6 +25,7 @@ #include <memory_resource> #include <atomic> #include <new> +#include <bits/std_mutex.h> namespace std _GLIBCXX_VISIBILITY(default) { @@ -81,7 +82,31 @@ namespace pmr constant_init<newdel_res_t> newdel_res{}; constant_init<null_res_t> null_res{}; +#if ATOMIC_POINTER_LOCK_FREE == 2 constant_init<atomic<memory_resource*>> default_res{&newdel_res.obj}; +#else + struct locking_atomic + { + constexpr locking_atomic(memory_resource* r) : val(r) { } + mutex mx; + memory_resource* val; + + memory_resource* load() + { + lock_guard<mutex> lock(mx); + return val; + } + + memory_resource* exchange(memory_resource* r) + { + lock_guard<mutex> lock(mx); + auto prev = val; + val = r; + return prev; + } + }; + constant_init<locking_atomic> default_res{&newdel_res.obj}; +#endif } // namespace memory_resource*