Module mutex
Available on crate feature
dep_sdl3
only.Expand description
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.
Structs§
- SDL_
Condition - A means to block multiple threads until a condition is satisfied.
- SDL_
Init State - A structure used for thread-safe initialization and shutdown.
- SDL_
Init Status - The current status of an
SDL_InitState
structure. - SDL_
Mutex - A means to serialize access to a resource between threads.
- SDL_
RWLock - A mutex that allows read-only threads to run in parallel.
- SDL_
Semaphore - A means to manage access to a resource, by count, between threads.
Constants§
- SDL_
INIT_ STATUS_ INITIALIZED - SDL_
INIT_ STATUS_ INITIALIZING - SDL_
INIT_ STATUS_ UNINITIALIZED - SDL_
INIT_ STATUS_ UNINITIALIZING
Functions§
- SDL_
Broadcast ⚠Condition - Restart all threads that are waiting on the condition variable.
- SDL_
Create ⚠Condition - Create a condition variable.
- SDL_
Create ⚠Mutex - Create a new mutex.
- SDL_
CreateRW ⚠Lock - Create a new read/write lock.
- SDL_
Create ⚠Semaphore - Create a semaphore.
- SDL_
Destroy ⚠Condition - Destroy a condition variable.
- SDL_
Destroy ⚠Mutex - Destroy a mutex created with
SDL_CreateMutex()
. - SDL_
DestroyRW ⚠Lock - Destroy a read/write lock created with
SDL_CreateRWLock()
. - SDL_
Destroy ⚠Semaphore - Destroy a semaphore.
- SDL_
GetSemaphore ⚠Value - Get the current value of a semaphore.
- SDL_
Lock ⚠Mutex - Lock the mutex.
- SDL_
LockRW ⚠Lock ForReading - Lock the read/write lock for read only operations.
- SDL_
LockRW ⚠Lock ForWriting - Lock the read/write lock for write operations.
- SDL_
SetInitialized ⚠ - Finish an initialization state transition.
- SDL_
Should ⚠Init - Return whether initialization should be done.
- SDL_
Should ⚠Quit - Return whether cleanup should be done.
- SDL_
Signal ⚠Condition - Restart one of the threads that are waiting on the condition variable.
- SDL_
Signal ⚠Semaphore - Atomically increment a semaphore’s value and wake waiting threads.
- SDL_
TryLock ⚠Mutex - Try to lock a mutex without blocking.
- SDL_
TryLockRW ⚠Lock ForReading - Try to lock a read/write lock for reading without blocking.
- SDL_
TryLockRW ⚠Lock ForWriting - Try to lock a read/write lock for writing without blocking.
- SDL_
TryWait ⚠Semaphore - See if a semaphore has a positive value and decrement it if it does.
- SDL_
Unlock ⚠Mutex - Unlock the mutex.
- SDL_
UnlockRW ⚠Lock - Unlock the read/write lock.
- SDL_
Wait ⚠Condition - Wait until a condition variable is signaled.
- SDL_
Wait ⚠Condition Timeout - Wait until a condition variable is signaled or a certain time has passed.
- SDL_
Wait ⚠Semaphore - Wait until a semaphore has a positive value and then decrements it.
- SDL_
Wait ⚠Semaphore Timeout - Wait until a semaphore has a positive value and then decrements it.