SDL_TryLockRWLockForReading(3)

πŸ’… SDL_TryLockRWLockForReading(3) ✨

aka the SDL3 function that's like "hey bestie, you free rn?" instead of standing there waiting forever πŸŽ€


🌸 NAME 🌸

SDL_TryLockRWLockForReading β€” try to lock a read/write lock for reading without blocking. no waiting, no lines, no drama πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <SDL3/SDL_mutex.h>

bool SDL_TryLockRWLockForReading(SDL_RWLock *rwlock);

✨ DESCRIPTION ✨

Okay so this works exactly like SDL_LockRWLockForReading(), except β€” and this is the whole moment β€” if the rwlock is not available, this function bails and returns false immediately. immediately immediately. Not "after a bit". Not "when it's polite". Right now. πŸ’€

This technique is useful if you need access to a resource but you don't want to wait around for it, and you'll come back and try again later. Like texting "u up?" and if they don't answer you just... go do something else. Main character energy honestly. πŸ‘‘

Trying to lock for read-only access can succeed even if other threads are holding read-only locks, because read-only stuff doesn't block other read-only stuff β€” nobody's fighting, everyone's just vibing with their own copy. 🫢

And a lil fun fact that lowkey matters: this function returns true if you pass it a NULL rwlock. Yes really. NULL gets the slay treatment. 😭


πŸ“ FUNCTION PARAMETERS πŸ“

  • rwlock β€” the rwlock you're trying to lock, bestie. the one and only. πŸŽ€

🌈 RETURN VALUE 🌈

Returns true on success, and false if the lock would block. That's it. That's the whole vibe check. ✨


πŸ”₯ THREAD SAFETY πŸ”₯

It is safe to call this function from any thread. any thread. every thread. go off, all of you. πŸ’…


πŸ‘‘ AVAILABILITY πŸ‘‘

This function is available since SDL 3.2.0. so if your SDL is older than that, she's not here yet, sorry bestie πŸ™ˆ


πŸ’œ SEE ALSO πŸ’œ


mwah πŸ’‹ this page came to you courtesy of Simple Directmedia Layer, version SDL 3.4.18 β€” stan an iconic library bestie, she's been holding it down fr fr πŸŒΈβœ¨πŸ’–

πŸ“¦ where this page comes from