Created
May 28, 2025 08:53
-
-
Save vurtun/7abc40e36ea1fa186e5e87584899ac45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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