From d84fa738ef4dabe569da8eace30fa409cf32519b Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 22 Jun 2002 15:55:01 +0000 Subject: [PATCH] Sleep(0) changed to Sleep(1) to (hopefully) avoid livelocks. [SVN r14226] --- include/boost/detail/lwm_win32.hpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/include/boost/detail/lwm_win32.hpp b/include/boost/detail/lwm_win32.hpp index a54aefc..0bc73bd 100644 --- a/include/boost/detail/lwm_win32.hpp +++ b/include/boost/detail/lwm_win32.hpp @@ -57,7 +57,12 @@ public: { while( winapi::InterlockedExchange(&m_.l_, 1) ) { - winapi::Sleep(0); + // Note: changed to Sleep(1) from Sleep(0). + // According to MSDN, Sleep(0) will never yield + // to a lower-priority thread, whereas Sleep(1) + // will. Performance seems not to be affected. + + winapi::Sleep(1); } } @@ -65,8 +70,8 @@ public: { winapi::InterlockedExchange(&m_.l_, 0); - // Note: adding a Sleep(0) here will make - // the mutex more fair and will increase the overall + // Note: adding a yield here will make + // the spinlock more fair and will increase the overall // performance of some applications substantially in // high contention situations, but will penalize the // low contention / single thread case up to 5x