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


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__)
#elif defined(_MSC_VER)
  while (InterlockedExchangeAcquire(spin, 1)) {
    while (*spin) {
      /* pass */

Instead of /*pass */, I’d assume that the Windows Macro YieldProcessor ( 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:

I’ve been told on the mailing list that the fix is in: