SDL_DetachThread(3)

πŸ’… SDL_DetachThread πŸ’…

okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, page SDL_DetachThread(3), and no cap this one is short but you gotta read it properly because threads do not forgive.


✨ NAME ✨

SDL_DetachThread β€” let a thread clean up on exit without intervention. it's giving "you go girl, handle your own business, I don't need to check up on you" πŸ¦‹


✨ SYNOPSIS ✨

#include <SDL3/SDL_thread.h>

void SDL_DetachThread(SDL_Thread *thread);

✨ DESCRIPTION ✨

so. a thread may be "detached" to signify that it should not remain until another thread has called SDL_WaitThread() on it. detaching a thread is useful for long-running threads that nothing needs to synchronize with or further manage. when a detached thread is done, it simply goes away. poof. iconic behavior honestly πŸ’…βœ¨

there is no way to recover the return code of a detached thread. like, it's gone, bestie. if you need this, don't detach the thread and instead use SDL_WaitThread(). periodt.

once a thread is detached, you should usually assume the SDL_Thread isn't safe to reference again, as it will become invalid immediately upon the detached thread's exit, instead of remaining until someone has called SDL_WaitThread() to finally clean it up. as such, don't detach the same thread more than once. not me warning you twice, that's just the rules 😭

if a thread has already exited when passed to SDL_DetachThread(), it will stop waiting for a call to SDL_WaitThread() and clean up immediately. and listen β€” it is not safe to detach a thread that might be used with SDL_WaitThread().

you may not call SDL_WaitThread() on a thread that has been detached. use either that function or this one, but not both, or behavior is undefined. πŸ™ˆ that's the scary kind of undefined too, the "we literally cannot tell you what happens" kind.

it is safe to pass NULL to this function; it is a no-op. so if you're worried about that one, breathe, you're fine 🫢


✨ FUNCTION PARAMETERS ✨

  • thread β€” the SDL_Thread pointer that was returned from the SDL_CreateThread() call that started this thread. like, the exact one, don't be passing random pointers around girlie πŸ’€

✨ THREAD SAFETY ✨

it is safe to call this function from any thread. yes, any. go off, main character energy πŸ‘‘


✨ AVAILABILITY ✨

this function is available since SDL 3.2.0. ⭐


✨ SEE ALSO ✨


and that's the whole vibe check, bestie πŸŽ€ this page is from Simple Directmedia Layer, version SDL 3.4.18 β€” so go detach responsibly, don't double-detach, and don't come crying to me when your return code is nowhere to be found πŸ’–πŸŒΈπŸ§š

πŸ“¦ where this page comes from