SDL_WaitCondition(3)

πŸ’– SDL_WaitCondition(3) πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, this one's about SDL_WaitCondition and it's lowkey the blueprint for how threads politely wait for each other 🫢


✨ NAME ✨

SDL_WaitCondition β€” wait until a condition variable is signaled. that's it, that's the whole vibe. sit there, look cute, wait for the signal πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_mutex.h>

void SDL_WaitCondition(SDL_Condition *cond, SDL_Mutex *mutex);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea β˜• this function unlocks the specified mutex and then just waits for another thread to call SDL_SignalCondition() or SDL_BroadcastCondition() on the condition variable cond. the way it's giving "i'll be right back, hold my spot" 😭

once the condition variable gets signaled, the mutex is re-locked and the function returns. like it left the group chat, got the notification, and immediately rejoined. no cap.

⚠️ bestie. the mutex must be locked before calling this function. locking the mutex recursively (more than once) is not supported and leads to undefined behavior. we do not do that here. πŸ™ˆ

and for the completionists: this function is the equivalent of calling SDL_WaitConditionTimeout() with a time length of -1. same energy, just the timeout flavor with the longest possible patience ✨


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • cond β€” the condition variable to wait on. the thing you're stalking. respectfully. πŸ‘€
  • mutex β€” the mutex used to coordinate thread access. the bouncer at the door, keeping everyone in line.

πŸ’œ THREAD SAFETY πŸ’œ

it is safe to call this function from any thread. literally any of them. everyone's invited, it's a whole party 🌈


⭐ AVAILABILITY ⭐

this function is available since SDL 3.2.0. so if you're on something older... babe, upgrade. πŸ’…


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, bestie!! this lil' slice of the manual lives in Simple Directmedia Layer's docs for SDL 3.4.18 β€” go forth and synchronize your threads responsibly πŸ§šβ€β™€οΈπŸ’–βœ¨

πŸ“¦ where this page comes from