SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
|
A delay for threads waiting for a shared resource. More...
#include <seqan3/utility/parallel/detail/spin_delay.hpp>
Public Member Functions | |
void | wait () |
Delays the calling thread by either using active spinning or passive spinning. | |
Constructors, destructor and assignment | |
constexpr | spin_delay () noexcept=default |
Defaulted. | |
constexpr | spin_delay (spin_delay const &) noexcept=default |
Defaulted. | |
constexpr | spin_delay (spin_delay &&) noexcept=default |
Defaulted. | |
constexpr spin_delay & | operator= (spin_delay const &) noexcept=default |
Defaulted. | |
constexpr spin_delay & | operator= (spin_delay &&) noexcept=default |
Defaulted. | |
~spin_delay () noexcept=default | |
Defaulted. | |
Private Member Functions | |
void | pause_processor () |
Efficient instruction to pause the CPU. | |
Private Attributes | |
int_fast32_t | current {1} |
The current waiting phase. | |
Static Private Attributes | |
static constexpr int_fast32_t | max_repetitions {16} |
The maximal number of repetitions until the thread yields. | |
A delay for threads waiting for a shared resource.
This spin delay is used in combination with spin locks. If the thread is waiting for a shared resource it will usually waste CPU cycles until it can acquire the lock. Especially if there is a high contention on the lock this can become a performance bottleneck. This spin delay allows for more efficient spinning phases using a hybrid spinning approach. At first it does active spinning until a certain number of wait cycles has been reached. After this the thread yields.
|
inline |
Delays the calling thread by either using active spinning or passive spinning.
In the first x repetitions the thread is paused using efficient CPU instructions. After x cycles of active spinning the thread will be suspended by invoking std::this_thread::yield.