[libcxx-commits] [libcxx] [libc++] Fix wait_on_destruct.pass.cpp hanging sometimes (PR #146240)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jun 30 06:06:20 PDT 2025
EricWF wrote:
> > This test was deadlocking on my machine.
> > It seems to me the intention of `in_async.wait(...)` was to wait for the value to be set to true, which requires a call of `wait(false)` (waits if value matches argument).
>
> Yes, I've got that backwards.
>
> > ~As a drive by change scoped_lock to unique_lock, since there shouldn't be any functional difference between the two in this test.~
> > I've addressed the issues with the `in_async` by switching to a condition variable instead, since my first attempt at fixing this with `in_async` wasn't sufficient.
>
> Could you elaborate? I just testted with changing `in_async.wait(true)` to `in_async.wait(false)` and it ran successfully 1000 times.
Yeah. So there's a race on `in_async`. If the async thread sets the value to true, then immediately sleeps, the main thread can run until completion, when the async thread wakes up it tries to call `notify_all` the stack containing `in_async` is gone.
https://github.com/llvm/llvm-project/pull/146240
More information about the libcxx-commits
mailing list