[libc++] Fix hang in counting_semaphore::try_acquire
authorArthur O'Dwyer <arthur.j.odwyer@gmail.com>
Thu, 4 Nov 2021 21:58:33 +0000 (17:58 -0400)
committerArthur O'Dwyer <arthur.j.odwyer@gmail.com>
Fri, 5 Nov 2021 19:57:46 +0000 (15:57 -0400)
commitc92a253cf0ddcf905707b4e9265b42570ce409d9
treefcaab6a9c27f80520298ee1223e5393677f10b78
parentbaa820c510d027911b464ee018e15217d09568da
[libc++] Fix hang in counting_semaphore::try_acquire

Before this patch, `try_acquire` blocks instead of returning false.
This is because `__libcpp_thread_poll_with_backoff` interprets zero
as meaning infinite, causing `try_acquire` to wait indefinitely.

Thanks to Pablo Busse (pabusse) for the patch!

Differential Revision: https://reviews.llvm.org/D98334
libcxx/include/semaphore
libcxx/test/std/thread/thread.semaphore/try_acquire.pass.cpp