Wiki Page Content


Use this function to try to lock a spin lock by setting it to a non-zero value.


SDL_bool SDL_AtomicTryLock(SDL_SpinLock* lock)

Function Parameters


a pointer to a lock variable

Return Value

Returns SDL_TRUE if the lock succeeded, SDL_FALSE if the lock is already held.

Code Examples

You can add your code example here


The atomic locks are efficient spinlocks using CPU instructions, but are vulnerable to starvation and can spin forever if a thread holding a lock has been terminated. For this reason you should minimize the code executed inside an atomic lock and never do expensive things like API or system calls while holding them.

/!\ The atomic locks are not safe to lock recursively.

CategoryAPI, CategoryAtomic

None: SDL_AtomicTryLock (last edited 2011-02-02 18:20:09 by SheenaSmith)

Please include your contact information if you'd like to receive a reply.