From 1cc140ac96b1cfd71af4d8af9dc59bdc74456c0e Mon Sep 17 00:00:00 2001 From: Chris Cotter Date: Sat, 17 Aug 2024 18:48:30 -0400 Subject: [PATCH] Relacy tests Instructions: git clone -b stdexec https://github.com/ccotter/relacy && cd relacy git clone -b relacy https://github.com/ccotter/stdexec CXX_STD=c++20 make build/test/stdexec/{async_scope_bug,split_bug} ./build/test/stdexec/split_bug --- include/exec/__detail/__bwos_lifo_queue.hpp | 4 ++-- include/exec/async_scope.hpp | 2 +- include/exec/start_now.hpp | 2 +- include/stdexec/__detail/__run_loop.hpp | 4 +++- include/stdexec/__detail/__when_all.hpp | 4 ++-- include/stdexec/stop_token.hpp | 10 +++++----- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/exec/__detail/__bwos_lifo_queue.hpp b/include/exec/__detail/__bwos_lifo_queue.hpp index 9d18f7284..149b5d648 100644 --- a/include/exec/__detail/__bwos_lifo_queue.hpp +++ b/include/exec/__detail/__bwos_lifo_queue.hpp @@ -152,7 +152,7 @@ namespace exec::bwos { block_type(block_size, allocator), allocator_of_t(allocator)) , mask_(blocks_.size() - 1) { - blocks_[owner_block_].reclaim(); + blocks_[owner_block_.load()].reclaim(); } template @@ -468,4 +468,4 @@ namespace exec::bwos { auto lifo_queue::block_type::is_stealable() const noexcept -> bool { return steal_tail_.load(std::memory_order_acquire) != block_size(); } -} // namespace exec::bwos \ No newline at end of file +} // namespace exec::bwos diff --git a/include/exec/async_scope.hpp b/include/exec/async_scope.hpp index d5e1c06e1..dedbfac79 100644 --- a/include/exec/async_scope.hpp +++ b/include/exec/async_scope.hpp @@ -781,7 +781,7 @@ namespace exec { // after this, which means we can rely on its self-ownership to ensure // that it is eventually deleted stdexec::start( - *new __op_t{nest(static_cast<_Sender&&>(__sndr)), static_cast<_Env&&>(__env), &__impl_}); + *(new __op_t{nest(static_cast<_Sender&&>(__sndr)), static_cast<_Env&&>(__env), &__impl_})); } template <__movable_value _Env = empty_env, sender_in<__env_t<_Env>> _Sender> diff --git a/include/exec/start_now.hpp b/include/exec/start_now.hpp index 557bf2bdf..b72640fcb 100644 --- a/include/exec/start_now.hpp +++ b/include/exec/start_now.hpp @@ -71,7 +71,7 @@ namespace exec { } void __complete() noexcept { - if (--__pending_ == 0) { + if (__pending_.fetch_sub(1) == 1) { auto __joiner = __joiner_.exchange(nullptr); if (__joiner) { __joiner->join(); diff --git a/include/stdexec/__detail/__run_loop.hpp b/include/stdexec/__detail/__run_loop.hpp index 0ce93821b..16f933a59 100644 --- a/include/stdexec/__detail/__run_loop.hpp +++ b/include/stdexec/__detail/__run_loop.hpp @@ -213,7 +213,9 @@ namespace stdexec { inline auto run_loop::__pop_front_() -> __task* { std::unique_lock __lock{__mutex_}; - __cv_.wait(__lock, [this] { return __head_.__next_ != &__head_ || __stop_; }); + while (!(__head_.__next_ != &__head_ || __stop_)) { + __cv_.wait(__mutex_); + } if (__head_.__tail_ == __head_.__next_) __head_.__tail_ = &__head_; return std::exchange(__head_.__next_, __head_.__next_->__next_); diff --git a/include/stdexec/__detail/__when_all.hpp b/include/stdexec/__detail/__when_all.hpp index 15c1b8d90..a6e3d00af 100644 --- a/include/stdexec/__detail/__when_all.hpp +++ b/include/stdexec/__detail/__when_all.hpp @@ -191,7 +191,7 @@ namespace stdexec { template void __arrive(_Receiver& __rcvr) noexcept { - if (0 == --__count_) { + if (1 == __count_.fetch_sub(1)) { __complete(__rcvr); } } @@ -361,7 +361,7 @@ namespace stdexec { } else if constexpr (!__same_as) { // We only need to bother recording the completion values // if we're not already in the "error" or "stopped" state. - if (__state.__state_ == __started) { + if (__state.__state_.load() == __started) { auto& __opt_values = __tup::get<__v<_Index>>(__state.__values_); using _Tuple = __decayed_tuple<_Args...>; static_assert( diff --git a/include/stdexec/stop_token.hpp b/include/stdexec/stop_token.hpp index 26e9e5a01..555134586 100644 --- a/include/stdexec/stop_token.hpp +++ b/include/stdexec/stop_token.hpp @@ -26,9 +26,9 @@ #include #include -#if __has_include() && __cpp_lib_jthread >= 201911 -# include -#endif +//#if __has_include() && __cpp_lib_jthread >= 201911 +//# include +//#endif namespace stdexec { namespace __stok { @@ -241,8 +241,8 @@ namespace stdexec { } // namespace __stok inline inplace_stop_source::~inplace_stop_source() { - STDEXEC_ASSERT((__state_.load(std::memory_order_relaxed) & __locked_flag_) == 0); - STDEXEC_ASSERT(__callbacks_ == nullptr); + //STDEXEC_ASSERT((__state_.load(std::memory_order_relaxed) & __locked_flag_) == 0); + //STDEXEC_ASSERT(__callbacks_ == nullptr); } inline auto inplace_stop_source::request_stop() noexcept -> bool {