SDL_TryLockRWLockForWriting(3)
SDL_TryLockRWLockForWriting(3) π
okay bestie, this one lives in the SDL3 FUNCTIONS corner of the manual and it is exactly the low-commitment lock you've been looking for. no waiting, no pining, no blocking. it's giving "if you're free, cool, if not, i'm literally walking away." π
β¨ NAME β¨
SDL_TryLockRWLockForWriting β try to lock a read/write lock for writing without blocking. π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_mutex.h>
bool SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock);
π DESCRIPTION π
so this works just like SDL_LockRWLockForWriting(), except β and this is the whole vibe β if the rwlock isn't available, it returns false immediately instead of making you sit there. no cap. π¦
this technique is chef's kiss when you need exclusive access to a resource but you do not want to wait around for it, and you're fully planning to come back and try again later. main character energy: you ask, you get told no, you move on with your day. β¨
π now the serious part, bestie, listen up. it is illegal for the owning thread to lock an already-locked rwlock for writing. read-only may be locked recursively β writing can not. doing so results in undefined behavior. not "kinda weird behavior," not "a warning," undefined. π
π also illegal: requesting a write lock from a thread that already holds a read-only lock. again: undefined behavior. you have to unlock the read-only lock before requesting a write lock. unlock first, then ask. periodt. π
and the cutest little quirk: this function returns true if you pass it a NULL rwlock. yeah. NULL? true. iconic behavior honestly. π
π«Ά FUNCTION PARAMETERS π«Ά
rwlockβ the rwlock to try to lock. that's the one. that's the whole list. π
β RETURN VALUE β
- Returns
trueon success π - Returns
falseif the lock would block π
π₯ THREAD SAFETY π₯
It is safe to call this function from any thread. any of them. all of them. go wild. πΈ
π AVAILABILITY π
This function is available since SDL 3.2.0. so if you're on something olderβ¦ bestie. upgrade. π§
π SEE ALSO π
and that's the page!! brought to you by Simple Directmedia Layer, running on SDL 3.4.18, filed under SDL_TryLockRWLockForWriting(3). go forth and try-lock responsibly, bestie π«Άπβ¨
π¦ 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