diff --git a/libs/pika/async_combinators/include/pika/async_combinators/when_some.hpp b/libs/pika/async_combinators/include/pika/async_combinators/when_some.hpp index 9282774c61..7882c338f3 100644 --- a/libs/pika/async_combinators/include/pika/async_combinators/when_some.hpp +++ b/libs/pika/async_combinators/include/pika/async_combinators/when_some.hpp @@ -178,6 +178,7 @@ namespace pika { # include # include +# include # include # include # include @@ -319,7 +320,7 @@ namespace pika { template struct when_some : std::enable_shared_from_this> //-V690 { - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; public: void on_future_ready(std::size_t idx, pika::execution::detail::agent_ref ctx) diff --git a/libs/pika/async_cuda/src/cuda_event_callback.cpp b/libs/pika/async_cuda/src/cuda_event_callback.cpp index 631f5bfc75..7ed3c380f1 100644 --- a/libs/pika/async_cuda/src/cuda_event_callback.cpp +++ b/libs/pika/async_cuda/src/cuda_event_callback.cpp @@ -13,10 +13,10 @@ #include #include #include +#include #include #include #include -#include #include #include @@ -59,7 +59,7 @@ namespace pika::cuda::experimental::detail { public: using event_callback_queue_type = concurrency::detail::ConcurrentQueue; using event_ready_queue_type = concurrency::detail::ConcurrentQueue; - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; using event_callback_vector_type = std::vector; // Background progress function for async CUDA operations. Checks for diff --git a/libs/pika/async_mpi/src/mpi_polling.cpp b/libs/pika/async_mpi/src/mpi_polling.cpp index 4de85822f5..e959b53a36 100644 --- a/libs/pika/async_mpi/src/mpi_polling.cpp +++ b/libs/pika/async_mpi/src/mpi_polling.cpp @@ -8,11 +8,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include @@ -53,7 +53,7 @@ namespace pika::mpi::experimental { // ----------------------------------------------------------------- /// Spinlock is used as it can be called by OS threads or pika tasks - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; // ----------------------------------------------------------------- /// Queries an environment variable to get/override a default value for diff --git a/libs/pika/concurrency/include/pika/concurrency/spinlock.hpp b/libs/pika/concurrency/include/pika/concurrency/spinlock.hpp index f5f8b5e4d1..16891fda92 100644 --- a/libs/pika/concurrency/include/pika/concurrency/spinlock.hpp +++ b/libs/pika/concurrency/include/pika/concurrency/spinlock.hpp @@ -9,27 +9,27 @@ #pragma once #include +#include #include #include #include +#include + namespace pika::concurrency::detail { - // Lockable spinlock class - // - // This is equivalent to pika::detail::spinlock with the addition of - // lock registration. struct spinlock { public: PIKA_NON_COPYABLE(spinlock); private: - pika::detail::spinlock m; + std::atomic v_; public: - spinlock(char const* /*desc*/ = nullptr) + spinlock(char const* const desc = "pika::concurrency::detail::spinlock") + : v_(false) { - PIKA_ITT_SYNC_CREATE(this, "pika::concurrency::detail::spinlock", ""); + PIKA_ITT_SYNC_CREATE(this, desc, ""); } ~spinlock() @@ -37,33 +37,86 @@ namespace pika::concurrency::detail { PIKA_ITT_SYNC_DESTROY(this); } - void lock() noexcept + void lock() { PIKA_ITT_SYNC_PREPARE(this); - m.lock(); + + // Checking for the value in is_locked() ensures that + // acquire_lock is only called when is_locked computes + // to false. This way we spin only on a load operation + // which minimizes false sharing that comes with an + // exchange operation. + // Consider the following cases: + // 1. Only one thread wants access critical section: + // is_locked() -> false; computes acquire_lock() + // acquire_lock() -> false (new value set to true) + // Thread acquires the lock and moves to critical + // section. + // 2. Two threads simultaneously access critical section: + // Thread 1: is_locked() || acquire_lock() -> false + // Thread 1 acquires the lock and moves to critical + // section. + // Thread 2: is_locked() -> true; execution enters + // inside while without computing acquire_lock(). + // Thread 2 yields while is_locked() computes to + // false. Then it retries doing is_locked() -> false + // followed by an acquire_lock() operation. + // The above order can be changed arbitrarily but + // the nature of execution will still remain the + // same. + do + { + util::yield_while([this] { return is_locked(); }, + "pika::concurrency::detail::spinlock::lock", false); + } while (!acquire_lock()); + PIKA_ITT_SYNC_ACQUIRED(this); util::register_lock(this); } - bool try_lock() noexcept + bool try_lock() { PIKA_ITT_SYNC_PREPARE(this); - if (m.try_lock()) + + bool r = acquire_lock(); //-V707 + + if (r) { PIKA_ITT_SYNC_ACQUIRED(this); util::register_lock(this); return true; } + PIKA_ITT_SYNC_CANCEL(this); return false; } - void unlock() noexcept + void unlock() { PIKA_ITT_SYNC_RELEASING(this); - m.unlock(); + + relinquish_lock(); + PIKA_ITT_SYNC_RELEASED(this); util::unregister_lock(this); } + + private: + // returns whether the mutex has been acquired + PIKA_FORCEINLINE bool acquire_lock() + { + return !v_.exchange(true, std::memory_order_acquire); + } + + // relinquish lock + PIKA_FORCEINLINE void relinquish_lock() + { + v_.store(false, std::memory_order_release); + } + + PIKA_FORCEINLINE bool is_locked() const + { + return v_.load(std::memory_order_relaxed); + } }; } // namespace pika::concurrency::detail diff --git a/libs/pika/errors/include/pika/errors/exception_list.hpp b/libs/pika/errors/include/pika/errors/exception_list.hpp index 532d47efa3..df9147f991 100644 --- a/libs/pika/errors/include/pika/errors/exception_list.hpp +++ b/libs/pika/errors/include/pika/errors/exception_list.hpp @@ -34,10 +34,6 @@ namespace pika { { private: /// \cond NOINTERNAL - - // TODO: Does this need to be pika::spinlock? - // using mutex_type = pika::spinlock; - // TODO: Add correct initialization of pika::util::detail spinlock. using mutex_type = pika::detail::spinlock; using exception_list_type = std::list; diff --git a/libs/pika/execution/include/pika/execution/algorithms/ensure_started.hpp b/libs/pika/execution/include/pika/execution/algorithms/ensure_started.hpp index c9dab9af79..b78255fd5c 100644 --- a/libs/pika/execution/include/pika/execution/algorithms/ensure_started.hpp +++ b/libs/pika/execution/include/pika/execution/algorithms/ensure_started.hpp @@ -16,6 +16,7 @@ # include # include # include +# include # include # include # include @@ -27,7 +28,6 @@ # include # include # include -# include # include # include # include @@ -123,7 +123,7 @@ namespace pika::ensure_started_detail { using allocator_type = typename std::allocator_traits::template rebind_alloc; PIKA_NO_UNIQUE_ADDRESS allocator_type alloc; - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; mutex_type mtx; pika::detail::atomic_count reference_count{0}; std::atomic start_called{false}; diff --git a/libs/pika/execution/include/pika/execution/algorithms/split.hpp b/libs/pika/execution/include/pika/execution/algorithms/split.hpp index b882a87d11..ce400198f4 100644 --- a/libs/pika/execution/include/pika/execution/algorithms/split.hpp +++ b/libs/pika/execution/include/pika/execution/algorithms/split.hpp @@ -16,6 +16,7 @@ # include # include # include +# include # include # include # include @@ -28,7 +29,6 @@ # include # include # include -# include # include # include # include @@ -123,7 +123,7 @@ namespace pika::split_detail { using allocator_type = typename std::allocator_traits::template rebind_alloc; PIKA_NO_UNIQUE_ADDRESS allocator_type alloc; - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; mutex_type mtx; pika::detail::atomic_count reference_count{0}; std::atomic start_called{false}; diff --git a/libs/pika/execution/include/pika/execution/algorithms/split_tuple.hpp b/libs/pika/execution/include/pika/execution/algorithms/split_tuple.hpp index 85d93fb588..258a64fd6e 100644 --- a/libs/pika/execution/include/pika/execution/algorithms/split_tuple.hpp +++ b/libs/pika/execution/include/pika/execution/algorithms/split_tuple.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -22,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -59,7 +59,7 @@ namespace pika::split_tuple_detail { using allocator_type = typename std::allocator_traits::template rebind_alloc; PIKA_NO_UNIQUE_ADDRESS allocator_type alloc; - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; mutex_type mtx; pika::detail::atomic_count reference_count{0}; std::atomic start_called{false}; diff --git a/libs/pika/execution/include/pika/execution/algorithms/sync_wait.hpp b/libs/pika/execution/include/pika/execution/algorithms/sync_wait.hpp index 5f5e0a28e3..19ccce8a63 100644 --- a/libs/pika/execution/include/pika/execution/algorithms/sync_wait.hpp +++ b/libs/pika/execution/include/pika/execution/algorithms/sync_wait.hpp @@ -13,6 +13,7 @@ #endif #include +#include #include #include #include @@ -20,7 +21,6 @@ #include #include #include -#include #include #include @@ -129,7 +129,7 @@ namespace pika::sync_wait_detail { #endif // We use a spinlock here to allow taking the lock on non-pika threads. - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; struct shared_state { diff --git a/libs/pika/executors/include/pika/executors/fork_join_executor.hpp b/libs/pika/executors/include/pika/executors/fork_join_executor.hpp index e2b8ef6a6e..e7d7fdf0a4 100644 --- a/libs/pika/executors/include/pika/executors/fork_join_executor.hpp +++ b/libs/pika/executors/include/pika/executors/fork_join_executor.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -20,7 +21,6 @@ #include #include #include -#include #include #include @@ -96,7 +96,7 @@ namespace pika::execution::experimental { struct region_data_type; using thread_function_helper_type = void(region_data_type&, std::size_t, std::size_t, - queues_type&, pika::spinlock&, std::exception_ptr&) noexcept; + queues_type&, pika::concurrency::detail::spinlock&, std::exception_ptr&) noexcept; // Members that change for each parallel region. struct region_data @@ -134,7 +134,7 @@ namespace pika::execution::experimental { std::size_t main_thread_; std::size_t num_threads_; - pika::spinlock exception_mutex_; + pika::concurrency::detail::spinlock exception_mutex_; std::exception_ptr exception_; // Data for each parallel region. @@ -185,7 +185,7 @@ namespace pika::execution::experimental { std::size_t const num_threads_; std::size_t const thread_index_; loop_schedule const schedule_; - pika::spinlock& exception_mutex_; + pika::concurrency::detail::spinlock& exception_mutex_; std::exception_ptr& exception_; std::uint64_t yield_delay_; @@ -366,7 +366,8 @@ namespace pika::execution::experimental { /// Main entry point for a single parallel region (static /// scheduling). static void call_static(region_data_type& rdata, std::size_t thread_index, - std::size_t num_threads, queues_type&, pika::spinlock& exception_mutex, + std::size_t num_threads, queues_type&, + pika::concurrency::detail::spinlock& exception_mutex, std::exception_ptr& exception) noexcept { region_data& data = rdata[thread_index].data_; @@ -410,7 +411,8 @@ namespace pika::execution::experimental { /// Main entry point for a single parallel region (dynamic /// scheduling). static void call_dynamic(region_data_type& rdata, std::size_t thread_index, - std::size_t num_threads, queues_type& queues, pika::spinlock& exception_mutex, + std::size_t num_threads, queues_type& queues, + pika::concurrency::detail::spinlock& exception_mutex, std::exception_ptr& exception) noexcept { region_data& data = rdata[thread_index].data_; diff --git a/libs/pika/futures/include/pika/futures/detail/future_data.hpp b/libs/pika/futures/include/pika/futures/detail/future_data.hpp index ca422b2846..9a8ce44ecf 100644 --- a/libs/pika/futures/include/pika/futures/detail/future_data.hpp +++ b/libs/pika/futures/include/pika/futures/detail/future_data.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -18,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -205,7 +205,7 @@ namespace pika::lcos::detail { template <> struct PIKA_EXPORT future_data_base : future_data_refcnt_base { - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; future_data_base() noexcept : state_(empty) diff --git a/libs/pika/futures/tests/unit/future.cpp b/libs/pika/futures/tests/unit/future.cpp index ee195d9867..db32b3651d 100644 --- a/libs/pika/futures/tests/unit/future.cpp +++ b/libs/pika/futures/tests/unit/future.cpp @@ -401,12 +401,12 @@ void test_future_for_string() PIKA_TEST_EQ(res, "foo"); } -pika::spinlock callback_mutex; +pika::concurrency::detail::spinlock callback_mutex; unsigned callback_called = 0; void wait_callback(pika::future) { - std::lock_guard lk(callback_mutex); + std::lock_guard lk(callback_mutex); ++callback_called; } @@ -443,7 +443,7 @@ void test_wait_callback() void do_nothing_callback(pika::lcos::local::promise& /*pi*/) { - std::lock_guard lk(callback_mutex); + std::lock_guard lk(callback_mutex); ++callback_called; } diff --git a/libs/pika/futures/tests/unit/shared_future.cpp b/libs/pika/futures/tests/unit/shared_future.cpp index f2c0fb6d00..fab94a5e4a 100644 --- a/libs/pika/futures/tests/unit/shared_future.cpp +++ b/libs/pika/futures/tests/unit/shared_future.cpp @@ -465,12 +465,12 @@ void test_shared_future_for_string() PIKA_TEST_EQ(res, "foo"); } -pika::spinlock callback_mutex; +pika::concurrency::detail::spinlock callback_mutex; unsigned callback_called = 0; void wait_callback(pika::shared_future) { - std::lock_guard lk(callback_mutex); + std::lock_guard lk(callback_mutex); ++callback_called; } @@ -509,7 +509,7 @@ void test_wait_callback() void do_nothing_callback(pika::lcos::local::promise& /*pi*/) { - std::lock_guard lk(callback_mutex); + std::lock_guard lk(callback_mutex); ++callback_called; } diff --git a/libs/pika/lcos/include/pika/lcos/and_gate.hpp b/libs/pika/lcos/include/pika/lcos/and_gate.hpp index 902d192b13..a3bc7cffed 100644 --- a/libs/pika/lcos/include/pika/lcos/and_gate.hpp +++ b/libs/pika/lcos/include/pika/lcos/and_gate.hpp @@ -8,11 +8,11 @@ #include #include +#include #include #include #include #include -#include #include #include @@ -25,7 +25,7 @@ namespace pika::lcos::local { /////////////////////////////////////////////////////////////////////////// - template + template struct base_and_gate { protected: diff --git a/libs/pika/lcos/include/pika/lcos/channel.hpp b/libs/pika/lcos/include/pika/lcos/channel.hpp index 07d33ec275..9b4e703c7d 100644 --- a/libs/pika/lcos/include/pika/lcos/channel.hpp +++ b/libs/pika/lcos/include/pika/lcos/channel.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -17,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -95,7 +95,7 @@ namespace pika::lcos::local { template class unlimited_channel : public channel_impl_base { - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; public: PIKA_NON_COPYABLE(unlimited_channel); @@ -389,7 +389,7 @@ namespace pika::lcos::local { template class one_element_channel : public channel_impl_base { - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; public: PIKA_NON_COPYABLE(one_element_channel); diff --git a/libs/pika/lcos/include/pika/lcos/receive_buffer.hpp b/libs/pika/lcos/include/pika/lcos/receive_buffer.hpp index 6f351cd73a..fc373493e4 100644 --- a/libs/pika/lcos/include/pika/lcos/receive_buffer.hpp +++ b/libs/pika/lcos/include/pika/lcos/receive_buffer.hpp @@ -9,10 +9,10 @@ #include #include +#include #include #include #include -#include #include #include @@ -23,7 +23,7 @@ namespace pika::lcos::local { /////////////////////////////////////////////////////////////////////////// - template + template struct receive_buffer { protected: diff --git a/libs/pika/lcos/include/pika/lcos/trigger.hpp b/libs/pika/lcos/include/pika/lcos/trigger.hpp index a74041cbe4..d753f23c41 100644 --- a/libs/pika/lcos/include/pika/lcos/trigger.hpp +++ b/libs/pika/lcos/include/pika/lcos/trigger.hpp @@ -8,12 +8,12 @@ #include #include +#include #include #include #include #include #include -#include #include #include @@ -24,7 +24,7 @@ namespace pika::lcos::local { /////////////////////////////////////////////////////////////////////////// - template + template struct base_trigger { protected: diff --git a/libs/pika/mpi_base/include/pika/mpi_base/mpi_environment.hpp b/libs/pika/mpi_base/include/pika/mpi_base/mpi_environment.hpp index a60a7b4c91..443103a2b9 100644 --- a/libs/pika/mpi_base/include/pika/mpi_base/mpi_environment.hpp +++ b/libs/pika/mpi_base/include/pika/mpi_base/mpi_environment.hpp @@ -10,9 +10,9 @@ #if defined(PIKA_HAVE_MODULE_MPI_BASE) +# include # include # include -# include # include # include @@ -59,7 +59,7 @@ namespace pika { namespace util { bool locked; }; - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; private: static mutex_type mtx_; diff --git a/libs/pika/resource_partitioner/include/pika/resource_partitioner/detail/partitioner.hpp b/libs/pika/resource_partitioner/include/pika/resource_partitioner/detail/partitioner.hpp index fb7c6de50b..5a57ffcd22 100644 --- a/libs/pika/resource_partitioner/include/pika/resource_partitioner/detail/partitioner.hpp +++ b/libs/pika/resource_partitioner/include/pika/resource_partitioner/detail/partitioner.hpp @@ -9,9 +9,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -74,7 +75,7 @@ namespace pika::resource::detail { /////////////////////////////////////////////////////////////////////// class partitioner { - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; public: partitioner(); diff --git a/libs/pika/runtime/include/pika/runtime/run_as_pika_thread.hpp b/libs/pika/runtime/include/pika/runtime/run_as_pika_thread.hpp index aa76c67592..8b4c64949a 100644 --- a/libs/pika/runtime/include/pika/runtime/run_as_pika_thread.hpp +++ b/libs/pika/runtime/include/pika/runtime/run_as_pika_thread.hpp @@ -8,8 +8,8 @@ #include #include +#include #include -#include #include #include @@ -33,7 +33,7 @@ namespace pika::threads { // NOTE: The condition variable needs be able to live past the scope // of this function. The mutex and boolean are guaranteed to live // long enough because of the lock. - pika::spinlock mtx; + pika::concurrency::detail::spinlock mtx; auto cond = std::make_shared(); bool stopping = false; @@ -63,7 +63,7 @@ namespace pika::threads { // Now signal to the waiting thread that we're done. { - std::lock_guard lk(mtx); + std::lock_guard lk(mtx); stopping = true; } cond->notify_all(); @@ -72,7 +72,7 @@ namespace pika::threads { pika::threads::detail::register_work(data); // wait for the pika thread to exit - std::unique_lock lk(mtx); + std::unique_lock lk(mtx); cond->wait(lk, [&]() -> bool { return stopping; }); // rethrow exceptions @@ -89,7 +89,7 @@ namespace pika::threads { // NOTE: The condition variable needs be able to live past the scope // of this function. The mutex and boolean are guaranteed to live // long enough because of the lock. - pika::spinlock mtx; + pika::concurrency::detail::spinlock mtx; auto cond = std::make_shared(); bool stopping = false; @@ -112,7 +112,7 @@ namespace pika::threads { // Now signal to the waiting thread that we're done. { - std::lock_guard lk(mtx); + std::lock_guard lk(mtx); stopping = true; } cond->notify_all(); @@ -121,7 +121,7 @@ namespace pika::threads { pika::threads::detail::register_work(data); // wait for the pika thread to exit - std::unique_lock lk(mtx); + std::unique_lock lk(mtx); cond->wait(lk, [&]() -> bool { return stopping; }); // rethrow exceptions diff --git a/libs/pika/runtime/include/pika/runtime/thread_mapper.hpp b/libs/pika/runtime/include/pika/runtime/thread_mapper.hpp index dcda42a0ae..9dcfcb834d 100644 --- a/libs/pika/runtime/include/pika/runtime/thread_mapper.hpp +++ b/libs/pika/runtime/include/pika/runtime/thread_mapper.hpp @@ -8,10 +8,10 @@ #pragma once #include +#include #include #include #include -#include #include #include @@ -139,7 +139,7 @@ namespace pika::util { os_thread_data get_os_thread_data(std::string const& label) const; private: - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; using thread_map_type = std::vector; using label_map_type = std::map; diff --git a/libs/pika/synchronization/CMakeLists.txt b/libs/pika/synchronization/CMakeLists.txt index cadfd30ea9..9e0d91ada3 100644 --- a/libs/pika/synchronization/CMakeLists.txt +++ b/libs/pika/synchronization/CMakeLists.txt @@ -27,8 +27,6 @@ set(synchronization_headers pika/synchronization/recursive_mutex.hpp pika/synchronization/shared_mutex.hpp pika/synchronization/sliding_semaphore.hpp - pika/synchronization/spinlock.hpp - pika/synchronization/spinlock_pool.hpp pika/synchronization/stop_token.hpp ) diff --git a/libs/pika/synchronization/docs/index.rst b/libs/pika/synchronization/docs/index.rst index eacf2f43f9..ab8606427e 100644 --- a/libs/pika/synchronization/docs/index.rst +++ b/libs/pika/synchronization/docs/index.rst @@ -25,7 +25,6 @@ the C++ standard ones in |pika| threads: * :cpp:class:`pika::recursive_mutex` * :cpp:class:`pika::shared_mutex` * :cpp:class:`pika::sliding_semaphore` -* :cpp:class:`pika::spinlock` (`std::mutex` compatible spinlock) * :cpp:class:`pika::detail::spinlock_pool` See :ref:`modules_lcos`, :ref:`modules_async_combinators`, and :ref:`modules_async` diff --git a/libs/pika/synchronization/include/pika/synchronization/barrier.hpp b/libs/pika/synchronization/include/pika/synchronization/barrier.hpp index e0bb731555..905da8f7bf 100644 --- a/libs/pika/synchronization/include/pika/synchronization/barrier.hpp +++ b/libs/pika/synchronization/include/pika/synchronization/barrier.hpp @@ -11,8 +11,8 @@ #include #include +#include #include -#include #include #include @@ -95,7 +95,7 @@ namespace pika { PIKA_NON_COPYABLE(barrier); private: - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; public: using arrival_token = bool; diff --git a/libs/pika/synchronization/include/pika/synchronization/channel_mpmc.hpp b/libs/pika/synchronization/include/pika/synchronization/channel_mpmc.hpp index c9e46701c4..916f8ef7c0 100644 --- a/libs/pika/synchronization/include/pika/synchronization/channel_mpmc.hpp +++ b/libs/pika/synchronization/include/pika/synchronization/channel_mpmc.hpp @@ -10,10 +10,10 @@ #include #include +#include #include #include #include -#include #include #include @@ -204,14 +204,7 @@ namespace pika::experimental { bool closed_; }; - //////////////////////////////////////////////////////////////////////////// - // For use with pika threads, the channel_mpmc defined here is the fastest - // (even faster than the channel_spsc). Using - // pika::concurrency::detail::spinlock as the means of synchronization - // enables the use of this channel with non-pika threads, however the - // performance degrades by a factor of ten compared to using - // pika::spinlock. template - using channel_mpmc = bounded_channel; + using channel_mpmc = bounded_channel; } // namespace pika::experimental diff --git a/libs/pika/synchronization/include/pika/synchronization/channel_mpsc.hpp b/libs/pika/synchronization/include/pika/synchronization/channel_mpsc.hpp index e29feabdb5..bb87483b65 100644 --- a/libs/pika/synchronization/include/pika/synchronization/channel_mpsc.hpp +++ b/libs/pika/synchronization/include/pika/synchronization/channel_mpsc.hpp @@ -10,10 +10,10 @@ #include #include +#include #include #include #include -#include #include #include @@ -209,6 +209,6 @@ namespace pika::experimental { // Using pika::concurrency::detail::spinlock as the means of synchronization // enables the use of this channel with non-pika threads. template - using channel_mpsc = base_channel_mpsc; + using channel_mpsc = base_channel_mpsc; } // namespace pika::experimental diff --git a/libs/pika/synchronization/include/pika/synchronization/condition_variable.hpp b/libs/pika/synchronization/include/pika/synchronization/condition_variable.hpp index 9dd3a24162..135f29b4f1 100644 --- a/libs/pika/synchronization/include/pika/synchronization/condition_variable.hpp +++ b/libs/pika/synchronization/include/pika/synchronization/condition_variable.hpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include diff --git a/libs/pika/synchronization/include/pika/synchronization/counting_semaphore.hpp b/libs/pika/synchronization/include/pika/synchronization/counting_semaphore.hpp index f681ef80f3..0524f17c52 100644 --- a/libs/pika/synchronization/include/pika/synchronization/counting_semaphore.hpp +++ b/libs/pika/synchronization/include/pika/synchronization/counting_semaphore.hpp @@ -8,8 +8,8 @@ #pragma once #include +#include #include -#include #include #include @@ -40,7 +40,8 @@ namespace pika { // well: one thread waiting for several other threads to touch (signal) // the semaphore, or several threads waiting for one other thread to touch // this semaphore. - template + template class counting_semaphore { public: @@ -159,7 +160,7 @@ namespace pika { }; /////////////////////////////////////////////////////////////////////////// - template + template class binary_semaphore : public counting_semaphore<1, Mutex> { public: diff --git a/libs/pika/synchronization/include/pika/synchronization/detail/condition_variable.hpp b/libs/pika/synchronization/include/pika/synchronization/detail/condition_variable.hpp index 3952549594..a378b69649 100644 --- a/libs/pika/synchronization/include/pika/synchronization/detail/condition_variable.hpp +++ b/libs/pika/synchronization/include/pika/synchronization/detail/condition_variable.hpp @@ -9,10 +9,10 @@ #include #include +#include #include #include #include -#include #include #include @@ -30,7 +30,7 @@ namespace pika::detail { PIKA_NON_COPYABLE(condition_variable); private: - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; private: // define data structures needed for intrusive slist container used for @@ -158,7 +158,7 @@ namespace pika::detail { struct condition_variable_data { - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; condition_variable_data() : count_(1) diff --git a/libs/pika/synchronization/include/pika/synchronization/detail/counting_semaphore.hpp b/libs/pika/synchronization/include/pika/synchronization/detail/counting_semaphore.hpp index cb9034083d..f1346b759d 100644 --- a/libs/pika/synchronization/include/pika/synchronization/detail/counting_semaphore.hpp +++ b/libs/pika/synchronization/include/pika/synchronization/detail/counting_semaphore.hpp @@ -8,8 +8,8 @@ #pragma once #include +#include #include -#include #include #include @@ -26,7 +26,7 @@ namespace pika::detail { class counting_semaphore { private: - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; public: PIKA_EXPORT counting_semaphore(std::ptrdiff_t value = 0); diff --git a/libs/pika/synchronization/include/pika/synchronization/detail/sliding_semaphore.hpp b/libs/pika/synchronization/include/pika/synchronization/detail/sliding_semaphore.hpp index a01eaa06ac..5ff52bc886 100644 --- a/libs/pika/synchronization/include/pika/synchronization/detail/sliding_semaphore.hpp +++ b/libs/pika/synchronization/include/pika/synchronization/detail/sliding_semaphore.hpp @@ -7,8 +7,8 @@ #pragma once #include +#include #include -#include #include #include @@ -25,7 +25,7 @@ namespace pika::detail { class sliding_semaphore { private: - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; public: PIKA_EXPORT sliding_semaphore(std::int64_t max_difference, std::int64_t lower_limit); diff --git a/libs/pika/synchronization/include/pika/synchronization/event.hpp b/libs/pika/synchronization/include/pika/synchronization/event.hpp index 535a8e807f..84ac556994 100644 --- a/libs/pika/synchronization/include/pika/synchronization/event.hpp +++ b/libs/pika/synchronization/include/pika/synchronization/event.hpp @@ -9,8 +9,8 @@ #include #include +#include #include -#include #include #include @@ -24,7 +24,7 @@ namespace pika::experimental { class event { private: - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; public: /// \brief Construct a new event semaphore diff --git a/libs/pika/synchronization/include/pika/synchronization/latch.hpp b/libs/pika/synchronization/include/pika/synchronization/latch.hpp index b1bc53bb38..dd69ad2a50 100644 --- a/libs/pika/synchronization/include/pika/synchronization/latch.hpp +++ b/libs/pika/synchronization/include/pika/synchronization/latch.hpp @@ -10,8 +10,8 @@ #include #include +#include #include -#include #include #include @@ -33,7 +33,7 @@ namespace pika { PIKA_NON_COPYABLE(latch); protected: - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; public: /// Initialize the latch diff --git a/libs/pika/synchronization/include/pika/synchronization/mutex.hpp b/libs/pika/synchronization/include/pika/synchronization/mutex.hpp index d842fb0185..38f541a119 100644 --- a/libs/pika/synchronization/include/pika/synchronization/mutex.hpp +++ b/libs/pika/synchronization/include/pika/synchronization/mutex.hpp @@ -8,12 +8,12 @@ #pragma once #include +#include #include #include #include #include #include -#include #include #include @@ -25,7 +25,7 @@ namespace pika { PIKA_NON_COPYABLE(mutex); protected: - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; public: PIKA_EXPORT mutex(char const* const description = ""); diff --git a/libs/pika/synchronization/include/pika/synchronization/recursive_mutex.hpp b/libs/pika/synchronization/include/pika/synchronization/recursive_mutex.hpp index 7904f4dc82..b0f8cb0160 100644 --- a/libs/pika/synchronization/include/pika/synchronization/recursive_mutex.hpp +++ b/libs/pika/synchronization/include/pika/synchronization/recursive_mutex.hpp @@ -12,9 +12,9 @@ #include #include +#include #include #include -#include #include #include @@ -24,7 +24,7 @@ namespace pika::detail { /// An exclusive-ownership recursive mutex which implements Boost.Thread's /// TimedLockable concept. - template + template struct recursive_mutex_impl { public: diff --git a/libs/pika/synchronization/include/pika/synchronization/sliding_semaphore.hpp b/libs/pika/synchronization/include/pika/synchronization/sliding_semaphore.hpp index 3f3dd6c057..84f82fe3dd 100644 --- a/libs/pika/synchronization/include/pika/synchronization/sliding_semaphore.hpp +++ b/libs/pika/synchronization/include/pika/synchronization/sliding_semaphore.hpp @@ -7,8 +7,8 @@ #pragma once #include +#include #include -#include #include #include @@ -41,7 +41,7 @@ namespace pika { /// allowed to proceed, but will make sure that the difference between /// the (arbitrary) number passed to set and wait does not exceed a given /// threshold. - template + template class sliding_semaphore_var { private: diff --git a/libs/pika/synchronization/include/pika/synchronization/spinlock.hpp b/libs/pika/synchronization/include/pika/synchronization/spinlock.hpp deleted file mode 100644 index 84568c61cf..0000000000 --- a/libs/pika/synchronization/include/pika/synchronization/spinlock.hpp +++ /dev/null @@ -1,130 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2011 Bryce Lelbach -// Copyright (c) 2011-2020 Hartmut Kaiser -// Copyright (c) 2014 Thomas Heller -// Copyright (c) 2008 Peter Dimov -// Copyright (c) 2018 Patrick Diehl -// Copyright (c) 2021 Nikunj Gupta -// -// SPDX-License-Identifier: BSL-1.0 -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -//////////////////////////////////////////////////////////////////////////////// - -#pragma once - -#include - -#include -#include -#include - -#include -#include -#include - -/////////////////////////////////////////////////////////////////////////////// -namespace pika { - // std::mutex-compatible spinlock class - struct spinlock - { - public: - PIKA_NON_COPYABLE(spinlock); - - private: - std::atomic v_; - - public: - spinlock(char const* const desc = "pika::spinlock") - : v_(false) - { - PIKA_ITT_SYNC_CREATE(this, desc, ""); - } - - ~spinlock() - { - PIKA_ITT_SYNC_DESTROY(this); - } - - void lock() - { - PIKA_ITT_SYNC_PREPARE(this); - - // Checking for the value in is_locked() ensures that - // acquire_lock is only called when is_locked computes - // to false. This way we spin only on a load operation - // which minimizes false sharing that comes with an - // exchange operation. - // Consider the following cases: - // 1. Only one thread wants access critical section: - // is_locked() -> false; computes acquire_lock() - // acquire_lock() -> false (new value set to true) - // Thread acquires the lock and moves to critical - // section. - // 2. Two threads simultaneously access critical section: - // Thread 1: is_locked() || acquire_lock() -> false - // Thread 1 acquires the lock and moves to critical - // section. - // Thread 2: is_locked() -> true; execution enters - // inside while without computing acquire_lock(). - // Thread 2 yields while is_locked() computes to - // false. Then it retries doing is_locked() -> false - // followed by an acquire_lock() operation. - // The above order can be changed arbitrarily but - // the nature of execution will still remain the - // same. - do - { - util::yield_while([this] { return is_locked(); }, "pika::spinlock::lock"); - } while (!acquire_lock()); - - PIKA_ITT_SYNC_ACQUIRED(this); - util::register_lock(this); - } - - bool try_lock() - { - PIKA_ITT_SYNC_PREPARE(this); - - bool r = acquire_lock(); //-V707 - - if (r) - { - PIKA_ITT_SYNC_ACQUIRED(this); - util::register_lock(this); - return true; - } - - PIKA_ITT_SYNC_CANCEL(this); - return false; - } - - void unlock() - { - PIKA_ITT_SYNC_RELEASING(this); - - relinquish_lock(); - - PIKA_ITT_SYNC_RELEASED(this); - util::unregister_lock(this); - } - - private: - // returns whether the mutex has been acquired - PIKA_FORCEINLINE bool acquire_lock() - { - return !v_.exchange(true, std::memory_order_acquire); - } - - // relinquish lock - PIKA_FORCEINLINE void relinquish_lock() - { - v_.store(false, std::memory_order_release); - } - - PIKA_FORCEINLINE bool is_locked() const - { - return v_.load(std::memory_order_relaxed); - } - }; -} // namespace pika diff --git a/libs/pika/synchronization/include/pika/synchronization/spinlock_pool.hpp b/libs/pika/synchronization/include/pika/synchronization/spinlock_pool.hpp deleted file mode 100644 index fc5341e9d1..0000000000 --- a/libs/pika/synchronization/include/pika/synchronization/spinlock_pool.hpp +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) 2012-2021 Hartmut Kaiser -// Copyright (c) 2014 Thomas Heller -// -// adapted from: -// boost/detail/spinlock_pool.hpp -// -// Copyright (c) 2008 Peter Dimov -// -// SPDX-License-Identifier: BSL-1.0 -// Distributed under the Boost Software License, Version 1.0. -// See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#pragma once - -#include -#include -#include -#include - -#include - -/////////////////////////////////////////////////////////////////////////////// -namespace pika::detail { - -#if PIKA_HAVE_ITTNOTIFY != 0 - template - struct itt_spinlock_init - { - itt_spinlock_init() noexcept; - ~itt_spinlock_init(); - }; -#endif - - template - class spinlock_pool - { - private: - static pika::concurrency::detail::cache_aligned_data pool_[N]; -#if PIKA_HAVE_ITTNOTIFY != 0 - static detail::itt_spinlock_init init_; -#endif - public: - static pika::spinlock& spinlock_for(void const* pv) noexcept - { - std::size_t i = pika::detail::fibhash(reinterpret_cast(pv)); - return pool_[i].data_; - } - - class scoped_lock - { - private: - pika::spinlock& sp_; - - public: - PIKA_NON_COPYABLE(scoped_lock); - - public: - explicit scoped_lock(void const* pv) - : sp_(spinlock_for(pv)) - { - lock(); - } - - ~scoped_lock() - { - unlock(); - } - - void lock() - { - PIKA_ITT_SYNC_PREPARE(&sp_); - sp_.lock(); - PIKA_ITT_SYNC_ACQUIRED(&sp_); - } - - void unlock() - { - PIKA_ITT_SYNC_RELEASING(&sp_); - sp_.unlock(); - PIKA_ITT_SYNC_RELEASED(&sp_); - } - }; - }; - - template - pika::concurrency::detail::cache_aligned_data spinlock_pool::pool_[N]; - -#if PIKA_HAVE_ITTNOTIFY != 0 - - template - itt_spinlock_init::itt_spinlock_init() noexcept - { - for (int i = 0; i < N; ++i) - { - PIKA_ITT_SYNC_CREATE( - (&pika::detail::spinlock_pool::pool_[i].data_), "pika::lcos::spinlock", 0); - PIKA_ITT_SYNC_RENAME( - (&pika::detail::spinlock_pool::pool_[i].data_), "pika::lcos::spinlock"); - } - } - - template - itt_spinlock_init::~itt_spinlock_init() - { - for (int i = 0; i < N; ++i) - { - PIKA_ITT_SYNC_DESTROY((&spinlock_pool::pool_[i].data_)); - } - } - - template - itt_spinlock_init spinlock_pool::init_{}; -#endif -} // namespace pika::detail diff --git a/libs/pika/synchronization/src/detail/condition_variable.cpp b/libs/pika/synchronization/src/detail/condition_variable.cpp index d04cdbb2aa..82b1ec5f57 100644 --- a/libs/pika/synchronization/src/detail/condition_variable.cpp +++ b/libs/pika/synchronization/src/detail/condition_variable.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/libs/pika/synchronization/src/detail/counting_semaphore.cpp b/libs/pika/synchronization/src/detail/counting_semaphore.cpp index efecd6cfbb..75b56f9516 100644 --- a/libs/pika/synchronization/src/detail/counting_semaphore.cpp +++ b/libs/pika/synchronization/src/detail/counting_semaphore.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include diff --git a/libs/pika/synchronization/src/detail/sliding_semaphore.cpp b/libs/pika/synchronization/src/detail/sliding_semaphore.cpp index 00ca9ec54f..61e9360d95 100644 --- a/libs/pika/synchronization/src/detail/sliding_semaphore.cpp +++ b/libs/pika/synchronization/src/detail/sliding_semaphore.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include diff --git a/libs/pika/synchronization/src/mutex.cpp b/libs/pika/synchronization/src/mutex.cpp index 79671a1a50..e00fadc420 100644 --- a/libs/pika/synchronization/src/mutex.cpp +++ b/libs/pika/synchronization/src/mutex.cpp @@ -8,12 +8,12 @@ #include #include +#include #include #include #include #include #include -#include #include #include #include diff --git a/libs/pika/synchronization/tests/regressions/ignore_while_locked_1485.cpp b/libs/pika/synchronization/tests/regressions/ignore_while_locked_1485.cpp index d41b98e770..42daeb1af0 100644 --- a/libs/pika/synchronization/tests/regressions/ignore_while_locked_1485.cpp +++ b/libs/pika/synchronization/tests/regressions/ignore_while_locked_1485.cpp @@ -20,7 +20,7 @@ struct wait_for_flag { - pika::spinlock mutex; + pika::concurrency::detail::spinlock mutex; pika::condition_variable_any cond_var; wait_for_flag() @@ -29,8 +29,8 @@ struct wait_for_flag { } - void wait( - pika::spinlock& local_mutex, pika::condition_variable_any& local_cond_var, bool& running) + void wait(pika::concurrency::detail::spinlock& local_mutex, + pika::condition_variable_any& local_cond_var, bool& running) { bool first = true; while (!flag) @@ -39,7 +39,7 @@ struct wait_for_flag if (first) { { - std::lock_guard lk(local_mutex); + std::lock_guard lk(local_mutex); running = true; } @@ -47,7 +47,7 @@ struct wait_for_flag local_cond_var.notify_all(); } - std::unique_lock lk(mutex); + std::unique_lock lk(mutex); if (!flag) { cond_var.wait(mutex); @@ -65,7 +65,7 @@ void test_condition_with_mutex() wait_for_flag data; bool running = false; - pika::spinlock local_mutex; + pika::concurrency::detail::spinlock local_mutex; pika::condition_variable_any local_cond_var; pika::thread thread(&wait_for_flag::wait, std::ref(data), std::ref(local_mutex), @@ -73,7 +73,7 @@ void test_condition_with_mutex() // wait for the thread to run { - std::unique_lock lk(local_mutex); + std::unique_lock lk(local_mutex); // NOLINTNEXTLINE(bugprone-infinite-loop) while (!running) local_cond_var.wait(lk); @@ -83,7 +83,7 @@ void test_condition_with_mutex() data.flag.store(true); { - std::lock_guard lock(data.mutex); + std::lock_guard lock(data.mutex); [[maybe_unused]] pika::util::ignore_all_while_checking il; data.cond_var.notify_one(); diff --git a/libs/pika/synchronization/tests/unit/fail_compile_spinlock_move.cpp b/libs/pika/synchronization/tests/unit/fail_compile_spinlock_move.cpp index b7a791dcac..c8b9e0ea66 100644 --- a/libs/pika/synchronization/tests/unit/fail_compile_spinlock_move.cpp +++ b/libs/pika/synchronization/tests/unit/fail_compile_spinlock_move.cpp @@ -6,14 +6,14 @@ // This must fail compiling -#include +#include #include /////////////////////////////////////////////////////////////////////////////// int main() { - using pika::spinlock; + using pika::concurrency::detail::spinlock; spinlock m1, m2(std::move(m1)); return 0; } diff --git a/libs/pika/thread_support/include/pika/thread_support/spinlock.hpp b/libs/pika/thread_support/include/pika/thread_support/spinlock.hpp index caa140d5b3..25a07ccf31 100644 --- a/libs/pika/thread_support/include/pika/thread_support/spinlock.hpp +++ b/libs/pika/thread_support/include/pika/thread_support/spinlock.hpp @@ -46,7 +46,7 @@ namespace pika::detail { void lock() noexcept { // Wait for lock to be released without generating cache misses - // Similar implementation to pika::spinlock + // Similar implementation to pika::concurrency::detail::spinlock unsigned k = 0; while (!try_lock()) { diff --git a/libs/pika/threading/include/pika/threading/thread.hpp b/libs/pika/threading/include/pika/threading/thread.hpp index 6590cd6053..8869369948 100644 --- a/libs/pika/threading/include/pika/threading/thread.hpp +++ b/libs/pika/threading/include/pika/threading/thread.hpp @@ -8,12 +8,12 @@ #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -40,7 +40,7 @@ namespace pika { class PIKA_EXPORT thread { - using mutex_type = pika::spinlock; + using mutex_type = pika::concurrency::detail::spinlock; void terminate(const char* function, const char* reason) const; public: diff --git a/libs/pika/threading/tests/unit/thread.cpp b/libs/pika/threading/tests/unit/thread.cpp index f0b36e65cf..045e1204bf 100644 --- a/libs/pika/threading/tests/unit/thread.cpp +++ b/libs/pika/threading/tests/unit/thread.cpp @@ -118,9 +118,9 @@ void test_id_comparison() } /////////////////////////////////////////////////////////////////////////////// -void interruption_point_thread(pika::spinlock* m, bool* failed) +void interruption_point_thread(pika::concurrency::detail::spinlock* m, bool* failed) { - std::unique_lock lk(*m); + std::unique_lock lk(*m); [[maybe_unused]] pika::util::ignore_while_checking il(&lk); pika::this_thread::interruption_point(); @@ -129,9 +129,9 @@ void interruption_point_thread(pika::spinlock* m, bool* failed) void do_test_thread_interrupts_at_interruption_point() { - pika::spinlock m; + pika::concurrency::detail::spinlock m; bool failed = false; - std::unique_lock lk(m); + std::unique_lock lk(m); pika::thread thrd(&interruption_point_thread, &m, &failed); thrd.interrupt(); lk.unlock(); @@ -146,13 +146,14 @@ void test_thread_interrupts_at_interruption_point() } /////////////////////////////////////////////////////////////////////////////// -void disabled_interruption_point_thread(pika::spinlock* m, pika::barrier<>* b, bool* failed) +void disabled_interruption_point_thread( + pika::concurrency::detail::spinlock* m, pika::barrier<>* b, bool* failed) { pika::this_thread::disable_interruption dc; b->arrive_and_wait(); try { - std::lock_guard lk(*m); + std::lock_guard lk(*m); pika::this_thread::interruption_point(); *failed = false; } @@ -166,7 +167,7 @@ void disabled_interruption_point_thread(pika::spinlock* m, pika::barrier<>* b, b void do_test_thread_no_interrupt_if_interrupts_disabled_at_interruption_point() { - pika::spinlock m; + pika::concurrency::detail::spinlock m; pika::barrier<> b(2); bool caught = false; bool failed = true; @@ -175,7 +176,7 @@ void do_test_thread_no_interrupt_if_interrupts_disabled_at_interruption_point() // marked itself to disable interrupts. try { - std::unique_lock lk(m); + std::unique_lock lk(m); [[maybe_unused]] pika::util::ignore_while_checking il(&lk); thrd.interrupt(); diff --git a/libs/pika/threading/tests/unit/tss.cpp b/libs/pika/threading/tests/unit/tss.cpp index 5ee5c4994a..f277c1b029 100644 --- a/libs/pika/threading/tests/unit/tss.cpp +++ b/libs/pika/threading/tests/unit/tss.cpp @@ -17,8 +17,8 @@ #include #include -pika::spinlock check_mutex; -pika::spinlock tss_mutex; +pika::concurrency::detail::spinlock check_mutex; +pika::concurrency::detail::spinlock tss_mutex; int tss_instances = 0; int tss_total = 0; @@ -27,14 +27,14 @@ struct tss_value_t tss_value_t(pika::lcos::local::promise pp) : p(std::move(pp)) { - std::unique_lock lock(tss_mutex); + std::unique_lock lock(tss_mutex); ++tss_instances; ++tss_total; value = 0; } ~tss_value_t() { - std::unique_lock lock(tss_mutex); + std::unique_lock lock(tss_mutex); --tss_instances; pika::util::ignore_while_checking il(&lock); p.set_value(); diff --git a/libs/pika/threading_base/src/set_thread_state.cpp b/libs/pika/threading_base/src/set_thread_state.cpp index 134fb08e65..07b27be9a0 100644 --- a/libs/pika/threading_base/src/set_thread_state.cpp +++ b/libs/pika/threading_base/src/set_thread_state.cpp @@ -133,7 +133,7 @@ namespace pika::threads::detail { else { pika::execution::this_thread::detail::yield_k( - k, "pika::threads::detail::set_thread_state"); + k % 16, "pika::threads::detail::set_thread_state"); ++k; // NOLINTNEXTLINE(bugprone-branch-clone) diff --git a/tests/regressions/threads/run_as_pika_thread_exceptions_3304.cpp b/tests/regressions/threads/run_as_pika_thread_exceptions_3304.cpp index f45cfdbfa4..59bc890a46 100644 --- a/tests/regressions/threads/run_as_pika_thread_exceptions_3304.cpp +++ b/tests/regressions/threads/run_as_pika_thread_exceptions_3304.cpp @@ -23,7 +23,7 @@ std::condition_variable startup_cond; bool running = false; bool stop_running = false; -int start_func(pika::spinlock& mtx, pika::condition_variable_any& cond) +int start_func(pika::concurrency::detail::spinlock& mtx, pika::condition_variable_any& cond) { // Signal to constructor that thread has started running. { @@ -32,7 +32,7 @@ int start_func(pika::spinlock& mtx, pika::condition_variable_any& cond) } { - std::unique_lock lk(mtx); + std::unique_lock lk(mtx); startup_cond.notify_one(); while (!stop_running) cond.wait(lk); @@ -48,7 +48,7 @@ void pika_thread_func() int main(int argc, char** argv) { - pika::spinlock mtx; + pika::concurrency::detail::spinlock mtx; pika::condition_variable_any cond; pika::util::detail::function start_function = @@ -76,7 +76,7 @@ int main(int argc, char** argv) PIKA_TEST(exception_caught); { - std::lock_guard lk(mtx); + std::lock_guard lk(mtx); stop_running = true; }