SDL_TryLockSpinlock(3)

πŸ’– SDL_TryLockSpinlock πŸ’–

okay bestie, gather round, we're in the SDL3 FUNCTIONS section of the manual and today's main character is SDL_TryLockSpinlock(3). she's a lil function that tries to lock a spin lock by setting it to a non-zero value. no drama, no waiting around, she just goes for it. πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_atomic.h>

bool SDL_TryLockSpinlock(SDL_SpinLock *lock);

like yes, that's the whole vibe. one include, one function, one pointer. iconic. πŸŽ€


🌸 DESCRIPTION 🌸

so real talk, bestie: spinlocks are dangerous if you don't know what you're doing. that's not me being dramatic, that's the manpage being dramatic and I'm just relaying it. 🫢

⚠️ Please be careful using any sort of spinlock! ⚠️

she said what she said. if you're not 100% sure about your locking situation, maybe sit this one out and let the pros handle it. iykyk. πŸ’€


πŸ¦‹ FUNCTION PARAMETERS πŸ¦‹

  • lock β€” a pointer to a lock variable. that's it, that's the whole shopping list. hand her the pointer and she'll do her thing. ✨

πŸ‘‘ RETURN VALUE πŸ‘‘

  • true β€” the lock succeeded, we ate, congrats. πŸ”₯
  • false β€” the lock is already held, so sorry bestie, someone else got there first. 😭

🧚 THREAD SAFETY 🧚

good news!! it is safe to call this function from any thread. go wild, go parallel, go feral (responsibly). 🌈


⭐ AVAILABILITY ⭐

this function is available since SDL 3.2.0. so if you're on anything older, no she's not there, don't @ me. πŸ™ˆ


πŸ’œ SEE ALSO πŸ’œ

the whole spinlock friend group, love that for them. πŸ“


Simple Directmedia Layer β€” SDL 3.4.18 β€” and that's the whole page, no cap. mwah, take care of those spinlocks for me bestie πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«ΆπŸ‘‘

πŸ“¦ where this page comes from