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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tomasz Kaminski <[email protected]>:

https://gcc.gnu.org/g:59889eaa2b4822389794bbb7793c4d7d391d9614

commit r16-4419-g59889eaa2b4822389794bbb7793c4d7d391d9614
Author: Tomasz KamiÅski <[email protected]>
Date:   Wed Aug 20 15:56:21 2025 +0200

    libstdc++: Make atomic<shared_ptr<T>>::wait sensitive to stored pointer
only changes [PR118757]

    Previously, atomic<shared_ptr<T>>::wait (and the weak_ptr version) was
    equivalent to waiting directly on _M_val, which corresponds to the pointer
    to the control block (_M_pi). Consequently, wakeups were not triggered if
    the stored pointer value was changed to a pointer that uses the same
control
    block but stores pointer to a different object. Such a pointer can be
    constructed using an aliasing constructor.

    To address this, wait now uses a generic proxy wait
    std::__atomic_wait_address function, which supports waiting until any
    predicate is satisfied. The provided predicate now compares both the
control
    block (_M_pi) and the stored pointer (_M_ptr). Comparing the latter
requires
    locking the pointer.

    Since this function operates on raw pointers, the type of _M_val was
changed
    from __atomic_base<uintptr_t> to uintptr_t. Invocations of the
corresponding
    member functions are now replaced with direct use of __atomic builtins.

            PR libstdc++/118757

    libstdc++-v3/ChangeLog:

            * include/bits/shared_ptr_atomic.h (_Atomic_count::_M_wait_unlock):
            Add parameter capturing reference to _M_ptr. Reimplement in terms
            of __atomic_wait_address.
            (_Atomic_count::~_Atomic_count, _Atomic_count::lock)
            (_Atomic_count::unlock, _Atomic_count::_M_swap_unlock): Replace
            invocation of atomic member funcitons with __atomic builtins.
            (_Atomic_count::notify_one, _Atomic_count::notify_all):
            Use __atomic_notify_address.
            (_Sp_atomic::element_type): Define.
            (_Sp_atomic::_M_val): Change type to uintptr_t.
            (_Sp_atomic::wait): Pass _M_ptr to _M_wait_unlock.
            * python/libstdcxx/v6/printers.py:
            * testsuite/20_util/shared_ptr/atomic/pr118757.cc: New test.
            * testsuite/20_util/weak_ptr/pr118757.cc: New test.

    Reviewed-by: Jonathan Wakely <[email protected]>
    Signed-off-by: Tomasz KamiÅski <[email protected]>

Reply via email to