SDL_WaitThread(3)
π SDL_WaitThread π
okay bestie, so this is a page from the SDL3 FUNCTIONS manual β the one and only SDL_WaitThread(3) β and we're gonna make it make sense, fr fr. no cap.
β¨ NAME β¨
SDL_WaitThread β bestie, it just waits for a thread to finish. that's the whole vibe. patient queen energy. π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_thread.h>
void SDL_WaitThread(SDL_Thread *thread, int *status);
π¦ DESCRIPTION π¦
okay so here's the tea: threads that haven't been detached will literally just stay there until this function comes along and cleans them up. and if you don't do it?? that's a resource leak. like, not cute at all. clean up after yourself, bestie. π§Ήβ¨
Once a thread has been cleaned up through this function, the SDL_Thread that references it becomes invalid and should not be referenced again. so likeβ¦ it's gone gone. π As such, only one thread may call SDL_WaitThread() on another. one waiter per thread, that's the rule, periodt.
The return code from the thread function gets placed in the area pointed to by status β if status is not NULL, obviously. if it is NULL, we just vibe and don't collect it.
β οΈ MAJOR WARNING β οΈ You may not wait on a thread that has been used in a call to SDL_DetachThread(). Use either that function or this one, but not both β or behavior is undefined. pick a lane, babes. π«
Good news tho: it is safe to pass a NULL thread to this function β it's a no-op. nothing happens. it's giving "I showed up but there was no party." π
Also note: the thread pointer is freed by this function and is not valid afterward. so don't go touching it after, iykyk. π
π FUNCTION PARAMETERS π
threadβ theSDL_Threadpointer that was returned from theSDL_CreateThread()call that started this thread. yes, the exact one. the og. the main character. βstatusβ a pointer filled in with the value returned from the thread function by its'return', or-1if the thread has been detached or isn't valid. may beNULL. so it's either the real answer,-1, or you just don't ask. π
π₯ THREAD SAFETY π₯
It is safe to call this function from any thread β everyone's invited to the function, no gatekeeping. π
BUT only a single thread can wait any specific thread to finish. one waiter per thread, we said it, we meant it. π«Ά
β AVAILABILITY β
This function is available since SDL 3.2.0. so if you're on something olderβ¦ bestie. upgrade. π
π SEE ALSO π
SDL_CreateThread(3)β the one that starts it all πSDL_DetachThread(3)β the other option (choose wisely, not both) π
and that's the whole page, bestie!! go forth and wait on your threads responsibly β one waiter, no leaks, no double-dipping with SDL_DetachThread, and don't touch the pointer after. slay. π
β¨
this lil manual page came from the Simple Directmedia Layer crew, it's SDL 3.4.18, and it's dated SDL_WaitThread(3) β mwah, ty for coming to my ted talk π«ΆπΈ
π¦ 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