SDL_UnlockMutex(3)

πŸ’– SDL_UnlockMutex β€” from the SDL3 FUNCTIONS girlies πŸ’–

okay bestie, so you've got a mutex, you locked it, and now you need to let it go πŸ¦‹ (the mutex, not the grudge). welcome to SDL_UnlockMutex, the third member of your little lock/unlock trio. this page is short but she is IMPORTANT, so read her fr fr.


✨ NAME ✨

SDL_UnlockMutex β€” unlock the mutex. that's it. that's the whole job. πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_mutex.h>

void SDL_UnlockMutex(SDL_Mutex *mutex);

look at her. returns nothing. takes one pointer. lowkey the calmest function in the whole header. 🌸


✨ DESCRIPTION ✨

okay so here's the tea β˜• and the tea is recursive mutexes.

It is legal for the owning thread to lock an already-locked mutex. but the way that it works is β€” you have to unlock it the exact same number of times before it's actually made available to other threads in the system. this whole situation is known as a "recursive mutex". so like, lock lock lock = unlock unlock unlock. balance, bestie. it's giving karma. βš–οΈβœ¨

now for the part where we get serious 😭:

It is illegal to unlock a mutex that has not been locked by the current thread, and doing so results in undefined behavior.

no cap. not "a little bad", not "a warning", undefined behavior. the vibes will not save you here. if your thread didn't lock it, your thread does NOT get to unlock it. periodt. πŸ’€πŸ™ˆ


✨ FUNCTION PARAMETERS ✨

  • mutex β€” the mutex to unlock. (yes queen, that exact one. the one you locked.) πŸ”“

✨ THREAD SAFETY ✨

This call must be paired with a previous locking call on the same thread. same thread, same mutex, matching energy. it's a buddy system, not a solo mission. 🫢


✨ AVAILABILITY ✨

This function is available since SDL 3.2.0. so if you're on something older, she's simply not there yet, and that's a you problem (affectionately). 🌈


✨ SEE ALSO ✨

go read the other two, they're the prequel and the chaotic cousin respectively. πŸ‘‘


and that's the whole page, babe. you just unlocked... well, *un*locked... your way through an entire manpage. main character energy, truly. 🌟

this lil love letter to concurrency comes to you from the fine folks at Simple Directmedia Layer, version SDL 3.4.18. mwah. stay locked, stay balanced, and always unlock exactly as many times as you locked. πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from