mutex topic

CategoryMutex

SDL offers several thread synchronization primitives. This document can't cover the complicated topic of thread safety, but reading up on what each of these primitives are, why they are useful, and how to correctly use them is vital to writing correct and safe multithreaded programs.

  • Mutexes: SDL_CreateMutex()
  • Read/Write locks: SDL_CreateRWLock()
  • Semaphores: SDL_CreateSemaphore()
  • Condition variables: SDL_CreateCondition()

SDL also offers a datatype, SDL_InitState, which can be used to make sure only one thread initializes/deinitializes some resource that several threads might try to use for the first time simultaneously.

Functions

sdlBroadcastCondition(Pointer<SdlCondition> cond) → void mutex
Restart all threads that are waiting on the condition variable.
sdlCreateCondition() Pointer<SdlCondition> mutex
Create a condition variable.
sdlCreateMutex() Pointer<SdlMutex> mutex
Create a new mutex.
sdlCreateRwLock() Pointer<SdlRwLock> mutex
Create a new read/write lock.
sdlCreateSemaphore(int initialValue) Pointer<SdlSemaphore> mutex
Create a semaphore.
sdlDestroyCondition(Pointer<SdlCondition> cond) → void mutex
Destroy a condition variable.
sdlDestroyMutex(Pointer<SdlMutex> mutex) → void mutex
Destroy a mutex created with SDL_CreateMutex().
sdlDestroyRwLock(Pointer<SdlRwLock> rwlock) → void mutex
Destroy a read/write lock created with SDL_CreateRWLock().
sdlDestroySemaphore(Pointer<SdlSemaphore> sem) → void mutex
Destroy a semaphore.
sdlGetSemaphoreValue(Pointer<SdlSemaphore> sem) int mutex
Get the current value of a semaphore.
sdlLockMutex(Pointer<NativeType> arg0) → void mutex
Lock the mutex.
sdlLockRwLockForReading(Pointer<NativeType> arg0) → void mutex
Lock the read/write lock for read only operations.
sdlLockRwLockForWriting(Pointer<NativeType> arg0) → void mutex
Lock the read/write lock for write operations.
sdlSetInitialized(Pointer<SdlInitState> state, bool initialized) → void mutex
Finish an initialization state transition.
sdlShouldInit(Pointer<SdlInitState> state) bool mutex
Return whether initialization should be done.
sdlShouldQuit(Pointer<SdlInitState> state) bool mutex
Return whether cleanup should be done.
sdlSignalCondition(Pointer<SdlCondition> cond) → void mutex
Restart one of the threads that are waiting on the condition variable.
sdlSignalSemaphore(Pointer<SdlSemaphore> sem) → void mutex
Atomically increment a semaphore's value and wake waiting threads.
sdlTryLockMutex(Pointer<NativeType> arg0, Pointer<NativeType> arg1) bool mutex
Try to lock a mutex without blocking.
sdlTryLockRwLockForReading(Pointer<NativeType> arg0, Pointer<NativeType> arg1) bool mutex
Try to lock a read/write lock for reading without blocking.
sdlTryLockRwLockForWriting(Pointer<NativeType> arg0, Pointer<NativeType> arg1) bool mutex
Try to lock a read/write lock for writing without blocking.
sdlTryWaitSemaphore(Pointer<SdlSemaphore> sem) bool mutex
See if a semaphore has a positive value and decrement it if it does.
sdlUnlockMutex(Pointer<NativeType> arg0) → void mutex
Unlock the mutex.
sdlUnlockRwLock(Pointer<NativeType> arg0) → void mutex
Unlock the read/write lock.
sdlWaitCondition(Pointer<SdlCondition> cond, Pointer<SdlMutex> mutex) → void mutex
Wait until a condition variable is signaled.
sdlWaitConditionTimeout(Pointer<SdlCondition> cond, Pointer<SdlMutex> mutex, int timeoutMs) bool mutex
Wait until a condition variable is signaled or a certain time has passed.
sdlWaitSemaphore(Pointer<SdlSemaphore> sem) → void mutex
Wait until a semaphore has a positive value and then decrements it.
sdlWaitSemaphoreTimeout(Pointer<SdlSemaphore> sem, int timeoutMs) bool mutex
Wait until a semaphore has a positive value and then decrements it.