SDL_LockMutex(3)
π SDL_LockMutex π
okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_LockMutex(3). grab a snack, we're locking a mutex π«Ά
β¨ NAME β¨
SDL_LockMutex β lock the mutex. that's it. that's the whole job. iconic, honestly π
β¨ SYNOPSIS β¨
#include <SDL3/SDL_mutex.h>
void SDL_LockMutex(SDL_Mutex *mutex);
β¨ DESCRIPTION β¨
so here's the vibe πΈ this function blocks until the mutex is available. and "available" means it's in the unlocked state and the OS has chosen the caller as the next thread to lock it. of all the threads waiting to lock that mutex, only one may do it at a time. no cutting the line, no group-chat pile-on. periodt π
now, plot twist: it is legal for the owning thread to lock an already-locked mutex π like, the thread that already holds it can lock it again. but β and this is the part where you gotta listen, bestie β it must unlock it the same number of times before the mutex is actually made available for other threads in the system. that's what we call a "recursive mutex" π lock it three times, unlock it three times, or everyone else is stuck waiting forever. no cap.
and here's the chill part: this function does not fail π if mutex is NULL, it will return immediately, having locked nothing. literally nothing happened, we just vibed and left π if the mutex is valid, this function will always block until it can lock the mutex, and return with it locked. so it either no-ops on you or it commits. no in-between.
no return value to check, no error code, no drama. it locks or it doesn't. that's the energy π
β¨ FUNCTION PARAMETERS β¨
mutexβ the mutex to lock. the one and only glow-up target π
β¨ THREAD SAFETY β¨
it is safe to call this function from any thread π go off, every thread, we love a function with no gatekeeping β
β¨ AVAILABILITY β¨
this function is available since SDL 3.2.0 π¦ so if you're on anything older, bestie, it's giving "not in your version" π
β¨ SEE ALSO β¨
SDL_TryLockMutex(3)β for when you're not about to wait around π«SDL_UnlockMutex(3)β the other half of the situationship, don't forget her π
Simple Directmedia Layer β SDL 3.4.18 π that's the source and version, mwah, thanks for reading bestie, go forth and lock responsibly, SDL_LockMutex(3) out π
β¨π«Ά
π¦ 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