Skip to content

Instantly share code, notes, and snippets.

@vurtun
Created May 28, 2025 08:53
Show Gist options
  • Save vurtun/7abc40e36ea1fa186e5e87584899ac45 to your computer and use it in GitHub Desktop.
Save vurtun/7abc40e36ea1fa186e5e87584899ac45 to your computer and use it in GitHub Desktop.
// https://danglingpointers.com/post/spinlock-implementation/
void Lock(AtomicI32& _spinLock)
{
for (;;)
{
if (_spinLock.load_Acquire() == 0)
{
i32 expected = 0;
i32 store = 1;
if (_spinLock.compareExchange_Acquire(expected, store))
break;
}
EMIT_PAUSE_INSTRUCTION();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment