diff --git a/src/corelib/thread/qfutureinterface.cpp b/src/corelib/thread/qfutureinterface.cpp index 71d66705383..a54caa878bb 100644 --- a/src/corelib/thread/qfutureinterface.cpp +++ b/src/corelib/thread/qfutureinterface.cpp @@ -45,6 +45,10 @@ #include #include +#ifdef Q_PROCESSOR_X86 +# include // for _mm_pause() +#endif + #ifdef interface # undef interface #endif @@ -106,9 +110,14 @@ static inline int switch_from_to(QAtomicInt &a, int from, int to) { int newValue; int expected = a.loadRelaxed(); - do { + for (;;) { newValue = (expected & ~from) | to; - } while (!a.testAndSetRelaxed(expected, newValue, expected)); + if (a.testAndSetRelaxed(expected, newValue, expected)) + break; +#ifdef Q_PROCESSOR_X86 + _mm_pause(); +#endif + } return newValue; }