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β theSDL_Threadpointer that was returned from theSDL_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
- 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