SDL_LockRWLockForReading(3)
π SDL_LockRWLockForReading(3) π
okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, this one's literally called SDL_LockRWLockForReading and it's about to be your new fave β¨
πΈ NAME πΈ
SDL_LockRWLockForReading β lock the read/write lock for read only operations, no cap π«Ά
π SYNOPSIS π
#include <SDL3/SDL_mutex.h>
void SDL_LockRWLockForReading(SDL_RWLock *rwlock);
β¨ DESCRIPTION β¨
okay so. this function will block until the rwlock is available, which is a fancy way of saying it's not locked for writing by any other thread. that's the whole vibe π
and here's the cute part: of all the threads waiting to lock the rwlock, all of them may do so at the same time as long as they're requesting read-only access. like, the more the merrier, group chat energy π
but if a thread wants to lock for writing? nope. only one may do so at a time, and no other threads β read-only or not β may hold the lock at the same time. exclusive. main character energy, truly π
not me about to tell you the recursive lore π it is legal for the owning thread to lock an already-locked rwlock for reading. slay! but it must unlock it the same number of times before it's actually made available for other threads in the system. this is what the girlies call a "recursive rwlock" β¨
π heads up: locking for writing is not recursive. that little perk is only available to read-only locks. periodt.
okay this next bit is the important one so pay attention bestie π
it is illegal to request a read-only lock from a thread that already holds the write lock. doing so results in undefined behavior. like, genuinely not the move. unlock the write lock before requesting a read-only lock π«Ά
(but, of course, if you already have the write lock, you don't need further locks to read in any case. iykyk π )
and the best news ever: this function does not fail π
- if
rwlockisNULL, it will return immediately having locked nothing. no drama, no error, just vibes. - if the
rwlockis valid, this function will always block until it can lock the mutex, and return with it locked. iconic behavior honestly π
π¦ FUNCTION PARAMETERS π¦
rwlockβ the read/write lock to lock. that's it, that's the whole parameter π
π THREAD SAFETY π
it is safe to call this function from any thread. yes bestie, ANY. go off π
β AVAILABILITY β
this function is available since SDL 3.2.0. so if you're on anything older... girl, upgrade π
π SEE ALSO π
Simple Directmedia Layer came through with this one, and this page is serving SDL 3.4.18 energy π«Ά go lock those read locks bestie, you got this, mwah πβ¨ππ¦
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms