Scroll to navigation

SDL_SpinLock(3type) SDL3 DATATYPES SDL_SpinLock(3type)

NAME

SDL_SpinLock - An atomic spinlock.

HEADER FILE

Defined in SDL3/SDL_atomic.h

SYNOPSIS

#include "SDL3/SDL.h"
typedef int SDL_SpinLock;

DESCRIPTION

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.

They are also vulnerable to starvation if the thread holding the lock is lower priority than other threads and doesn't get scheduled. In general you should use mutexes instead, since they have better performance and contention behavior.

The atomic locks are not safe to lock recursively.

Porting Note: The spin lock functions and type are required and can not be emulated because they are used in the atomic emulation code.

SDL 3.1.2 Simple Directmedia Layer