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

--- Comment #8 from dave.anglin at bell dot net ---
On 2018-08-11 8:04 PM, redi at gcc dot gnu.org wrote:
> 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:
The testsuite isn't quite finished but it's clear this fixes the bug on 
hppa64-hp-hpux11.11.
Don't know about second patch.
>
> --- 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*
>

Thanks,
Dave

Reply via email to