https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118757
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2025-02-05
Status|UNCONFIRMED |NEW
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
There's no such requirement in the standard, it's perfectly valid for p.wait(q)
to take more than a second to wake up.
But the bug is real, we fail to wake up at all.
Here's a version that the standard requires to exit normally, without assuming
p.wait(q) executes in less than a second:
#include <memory>
#include <chrono>
#include <thread>
#include <barrier>
std::shared_ptr<int> q = std::make_shared<int>(42);
std::atomic<std::shared_ptr<int>> p = q;
std::barrier bar(2);
void signaler()
{
std::this_thread::sleep_for(std::chrono::seconds(1));
p.store({ q, nullptr });
p.notify_one();
bar.arrive_and_wait();
}
int main(int, char**)
{
std::thread thr(signaler);
p.wait(q);
bar.arrive_and_wait();
thr.join();
}