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