public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/114865] New: std::atomic<X>::compare_exchange_strong seems to hang under GCC 13 on Ubuntu 23.04
@ 2024-04-26 15:50 pdimov at gmail dot com
  2024-04-26 17:47 ` [Bug libstdc++/114865] " pdimov at gmail dot com
                   ` (21 more replies)
  0 siblings, 22 replies; 23+ messages in thread
From: pdimov at gmail dot com @ 2024-04-26 15:50 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114865
           Summary: std::atomic<X>::compare_exchange_strong seems to hang
                    under GCC 13 on Ubuntu 23.04
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pdimov at gmail dot com
  Target Milestone: ---

I'm getting weird hangs on Github Actions when using
`std::atomic<state_type>::compare_exchange_strong` under GCC 13 on Ubuntu 23.04
(only; GCC 12 and earlier on Ubuntu 22.04 and earlier work). `state_type` is
defined as

```
struct state_type
{
    std::uint64_t timestamp;
    std::uint16_t clock_seq;
};
```

and the code doing the CAS is

```
auto oldst = ps_->load( std::memory_order_relaxed );

for( ;; )
{
    auto newst = get_new_state( oldst );

    if( ps_->compare_exchange_strong( oldst, newst, std::memory_order_relaxed,
std::memory_order_relaxed ) )
    {
        state_ = newst;
        break;
    }
}
```

where `ps` is of type `std::atomic<state_type>*`.

At a glance, I see nothing immediately wrong with the generated code
(https://godbolt.org/z/8Ee3hrTz8).

However, when I change `state_type` to

```
struct state_type
{
    std::uint64_t timestamp;
    std::uint16_t clock_seq;
    std::uint16_t padding[ 3 ];
};
```
the hangs disappear. This leads me to think that the problem is caused by the
original struct having padding, which isn't being handled correctly for some
reason.

As we know, `std::atomic<T>::compare_exchange_strong` is carefully specified to
take and return `expected` by reference, such that it can both compare the
entire object as if via `memcmp` (including the padding), and return it as if
by `memcpy`, again including the padding. Even though the padding bits of the
initial value returned by the atomic load are unspecified, at most one
iteration of the loop would be required for the padding bits to converge and
for the CAS to succeed.

However, going by the symptoms alone, this doesn't seem to be the case here.

The problem may well be inside libatomic, of course; I have no way to tell.

One GHA run showing the issue is
https://github.com/boostorg/uuid/actions/runs/8821753835, where only the GCC 13
job times out.

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2024-05-21  9:20 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-26 15:50 [Bug libstdc++/114865] New: std::atomic<X>::compare_exchange_strong seems to hang under GCC 13 on Ubuntu 23.04 pdimov at gmail dot com
2024-04-26 17:47 ` [Bug libstdc++/114865] " pdimov at gmail dot com
2024-04-26 19:40 ` pdimov at gmail dot com
2024-04-26 23:14 ` [Bug libstdc++/114865] [13/14/15 Regression] " pinskia at gcc dot gnu.org
2024-04-26 23:16 ` pinskia at gcc dot gnu.org
2024-04-27  0:13 ` pdimov at gmail dot com
2024-04-27  0:16 ` pinskia at gcc dot gnu.org
2024-04-27  0:16 ` pinskia at gcc dot gnu.org
2024-04-27  0:22 ` pinskia at gcc dot gnu.org
2024-04-27  0:25 ` pinskia at gcc dot gnu.org
2024-04-27  0:29 ` pdimov at gmail dot com
2024-04-27  0:31 ` pdimov at gmail dot com
2024-04-27  0:35 ` [Bug libstdc++/114865] [13/14/15 Regression] std::atomic<X>::compare_exchange_strong seems to hang under GCC 13 for C++11 pinskia at gcc dot gnu.org
2024-04-27  0:38 ` pdimov at gmail dot com
2024-04-27  0:42 ` pinskia at gcc dot gnu.org
2024-04-27  0:42 ` pdimov at gmail dot com
2024-05-02 11:40 ` redi at gcc dot gnu.org
2024-05-02 11:41 ` redi at gcc dot gnu.org
2024-05-02 11:44 ` redi at gcc dot gnu.org
2024-05-02 11:47 ` redi at gcc dot gnu.org
2024-05-02 11:55 ` redi at gcc dot gnu.org
2024-05-02 15:13 ` pdimov at gmail dot com
2024-05-21  9:20 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).