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 β€” the SDL_Thread pointer that was returned from the SDL_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 -1 if the thread has been detached or isn't valid. may be NULL. 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 πŸ’€


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