From 72ca834ae8a86cef59035a05042988298715269c Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 7 Jun 2020 21:24:21 +0300 Subject: [PATCH] Change yield_k to not use sp_thread_yield; using sp_thread_sleep is always strictly superior, at least on Windows --- include/boost/smart_ptr/detail/yield_k.hpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/include/boost/smart_ptr/detail/yield_k.hpp b/include/boost/smart_ptr/detail/yield_k.hpp index 367e022..8f52a58 100644 --- a/include/boost/smart_ptr/detail/yield_k.hpp +++ b/include/boost/smart_ptr/detail/yield_k.hpp @@ -175,14 +175,17 @@ namespace detail inline void yield( unsigned k ) BOOST_NOEXCEPT { - if( k < 16 ) + // Experiments show that a simple sp_thread_sleep() here is best; + // leave a few pause instructions out of mostly superstition. + // (These are verified to not degrade performance.) + // + // There seems to be no benefit from calling sp_thread_yield() + // at any time. + + if( k < 8 ) { BOOST_SMT_PAUSE } - else if( k < 32 ) - { - sp_thread_yield(); - } else { sp_thread_sleep();