SDL_RWLock(3type)

SDL_RWLock πŸ’–

okay bestie, welcome to the SDL3 DATATYPES section of the manual, we're talking about SDL_RWLock today and honestly? she's iconic. πŸŽ€


✨ NAME ✨

SDL_RWLock β€” a mutex that lets the read-only girlies run in parallel. πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_mutex.h>

typedef struct SDL_RWLock SDL_RWLock;

✨ DESCRIPTION ✨

so a rwlock is roughly the same concept as SDL_Mutex, but here's the plot twist: it lets threads that are asking for read-only access all hold the lock at the same time. no fighting, no queueing, they all just vibe together. πŸ¦‹

but the second a thread wants write access? okay so she blocks. that thread waits until <em>all</em> the read-only threads have released the lock, and then no one else can hold the thread (for reading or writing) at the same time as the writing thread. exclusive. main character energy only. πŸ‘‘

this can be more efficient in cases where several threads need to access data frequently, but changes to that data are <em>rare</em>. lots of readers, barely any writers? that's the rwlock sweet spot fr fr. ✨

heads up though β€” there are other rules that apply to rwlocks that don't apply to mutexes, all about how threads are scheduled and when they can be recursively locked. those are documented in the other rwlock functions, so go read those too bestie, don't skip them. πŸ™ˆ

✨ AVAILABILITY ✨

this struct is available since SDL 3.2.0. πŸ’œ


and that's the whole page, no cap. this one came from the Simple Directmedia Layer girlies, version SDL 3.4.18, dated all the way back in the SDL_RWLock(3type) era β€” mwah, obsessed, bye bestie! πŸ«ΆπŸŒΈπŸ’–

πŸ“¦ where this page comes from