SDL_CreateMutex(3)

πŸ’– SDL_CreateMutex(3) β€” SDL3 FUNCTIONS πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_CreateMutex πŸŽ€


✨ NAME ✨

SDL_CreateMutex β€” Create a new mutex. that's it, that's the vibe πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_mutex.h>

SDL_Mutex * SDL_CreateMutex(void);

like, you include the header, you call the function, no arguments, we love a no-argument icon πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so when you make a mutex, it starts off in the _unlocked_ state. brand new, unlocked, fresh out the box, no cap ✨

and here's the tea: when you call SDL_LockMutex(), it will NOT return while that mutex is locked by another thread. it just sits there. waiting. patient. main character energy fr fr 😭 if you don't wanna block like that, go look at SDL_TryLockMutex() instead β€” that one attempts to lock without blocking 🫢

also important: SDL mutexes are reentrant. yes bestie, reentrant. iykyk πŸ’š


🌈 RETURN VALUE 🌈

it returns the initialized and unlocked mutex, or NULL on failure 😭 and if you get NULL, call SDL_GetError() for more information. always check, bestie, always check πŸ’€


πŸ”₯ THREAD SAFETY πŸ”₯

it is safe to call this function from any thread. any thread. all the threads. slay πŸ‘‘


⭐ AVAILABILITY ⭐

this function is available since SDL 3.2.0. periodt πŸ’…


πŸ’œ SEE ALSO πŸ’œ

go read those too, they're literally the rest of the story πŸŽ€


and that's a wrap, bestie!! this page is brought to you by Simple Directmedia Layer, SDL 3.4.18, and it's giving SDL_CreateMutex(3) energy πŸ¦‹βœ¨ mwah, ily, go lock something πŸ’–

πŸ“¦ where this page comes from