Windows threading question: why no _mm_pause / yield in the spinlock implementation?

Hey,

Out of curiosity, why is there no “yield” statement in the spinlock implementation in “source/blender/blenlib/intern/threads.c”?

void BLI_spin_lock(SpinLock *spin)
{
#if defined(__APPLE__)
  OSSpinLockLock(spin);
#elif defined(_MSC_VER)
  while (InterlockedExchangeAcquire(spin, 1)) {
    while (*spin) {
      /* pass */
    }
  }
#else
  pthread_spin_lock(spin);
#endif
}

Instead of /*pass */, I’d assume that the Windows Macro YieldProcessor (https://msdn.microsoft.com/en-us/library/windows/desktop/ms687419(v=vs.85).aspx) should be used here.

Basically, YieldProcessor (which compiles into the “pause” or “rep nop” assembly instructions) is a special x86 assembly instruction that says “Give resources to the hyperthread-sibling”. Since you’re spinning uselessly in a loop, might as well let your hyperthread-brother do some more work, right?

See here for more information on the _mm_pause instruction: https://software.intel.com/en-us/node/524249

I’ve been told on the mailing list that the fix is in: https://developer.blender.org/rBef502854feb6b81119954206bff414d4507f4f3c