SDL_WaitConditionTimeout(3)

πŸ’– SDL_WaitConditionTimeout πŸ’–

okay bestie, so you know how there's a whole SDL3 FUNCTIONS manual situation? yeah, this is one of those pages, and it's literally about waiting for a condition variable to get signaled β€” or just... giving up after a while. the vibe is patience with a deadline. πŸ•°οΈβœ¨


🌸 NAME 🌸

SDL_WaitConditionTimeout β€” wait until a condition variable is signaled, or until a certain amount of time has passed. no cap. ⏳


✨ SYNOPSIS ✨

#include <SDL3/SDL_mutex.h>

bool SDL_WaitConditionTimeout(SDL_Condition *cond,
                    SDL_Mutex *mutex, Sint32 timeoutMS);

πŸŽ€ DESCRIPTION πŸŽ€

okay so here's the tea. this function unlocks the mutex you hand it and then it just... waits. it's waiting for another thread to hit it with SDL_SignalCondition() or SDL_BroadcastCondition() on the condition variable cond β€” or for the specified time to run out. whichever comes first, bestie. once the condition variable gets signaled or the clock says "we're done here", the mutex gets re-locked and the function returns. πŸ’…

🚨 real talk though: the mutex must be locked before you call this function. that's non-negotiable. and do NOT lock the mutex recursively (like, more than once). it is not supported and it leads to undefined behavior. not the cute mysterious kind of undefined. the bad kind. πŸ’€

🫢 FUNCTION PARAMETERS 🫢

  • cond β€” the condition variable you're waiting on. your main character. πŸ‘‘
  • mutex β€” the mutex that coordinates thread access. it keeps everybody in line fr fr. πŸ”’
  • timeoutMS β€” the maximum time to wait, measured in milliseconds, or -1 if you want to wait indefinitely. yes, -1 means "forever, bestie." 🌈

⭐ RETURN VALUE ⭐

  • returns true if the condition variable got signaled πŸŽ‰
  • returns false if the condition was not signaled within the allotted time 😭

🧚 THREAD SAFETY 🧚

it is safe to call this function from any thread. every thread. all of them. go off. πŸ¦‹


🌸 AVAILABILITY 🌸

this function is available since SDL 3.2.0. iconic behavior honestly. ✨


πŸ”₯ SEE ALSO πŸ”₯


and that's the whole page, bestie!! πŸŽ€ go forth and synchronize your threads responsibly, mwah πŸ’œ

this little love letter to concurrency comes to you courtesy of Simple Directmedia Layer, version SDL 3.4.18 β€” SDL_WaitConditionTimeout(3), signing off 🫢✨

πŸ“¦ where this page comes from