SDL_LockRWLockForWriting(3)

πŸ’– SDL_LockRWLockForWriting πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS page for SDL_LockRWLockForWriting(3) β€” yes the whole manual name is in there, we're being ✨proper✨ today.


🌸 NAME 🌸

SDL_LockRWLockForWriting β€” lock the read/write lock for write operations. that's it. that's the job. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <SDL3/SDL_mutex.h>

void SDL_LockRWLockForWriting(SDL_RWLock *rwlock);

✨ DESCRIPTION ✨

so here's the tea β˜• β€” this function will block until the rwlock is actually available, which means: not locked for reading or writing by any other thread. periodt.

Only one thread may hold the lock when it requests write access. everybody else β€” whether they also wanna write or they only want read-only access β€” has to wait until the writer thread has released the lock. no cutting the line, no exceptions. 🫢

🚨 now the serious part, bestie, pay attention:

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", literally undefined. do not. 😭

It is also illegal to request a write lock from a thread that already holds a read-only lock. Doing so results in undefined behavior. So unlock the read-only lock before you request a write lock. the order matters, iykyk. πŸ’€

Okay but here's the comforting part: this function does not fail. if rwlock is NULL, it will return immediately having locked nothing. if the rwlock is valid, this function will always block until it can lock the mutex, and return with it locked. reliable king behavior. πŸ‘‘πŸ’–


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • rwlock β€” the read/write lock to lock. that's the one. the only one. give it the rwlock. 🌸

🌈 THREAD SAFETY 🌈

It is safe to call this function from any thread. yes, any. go wild (responsibly). ✨


⭐ AVAILABILITY ⭐

This function is available since SDL 3.2.0. so if you're on something older… girl. upgrade. πŸ™ˆ


πŸ’œ SEE ALSO πŸ’œ

go read those too, they're the friend group. 🧚


and that's the whole page, bestie!! this was brought to you by Simple Directmedia Layer, version SDL 3.4.18, on the SDL_LockRWLockForWriting(3) page. lock responsibly, unlock always, and remember: writing can NOT be recursive. mwah πŸ’‹πŸ’…βœ¨

πŸ“¦ where this page comes from