SDL_CreateThread(3)

πŸ’– SDL_CreateThread πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS corner of the SDL_CreateThread(3) page β€” yes that's the manual name, we're keeping it, it's iconic. let's get you a whole new thread fr fr 🧡✨


✨ NAME ✨

SDL_CreateThread β€” spin up a brand new thread with a default stack size. that's it, that's the whole vibe. πŸ¦‹


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_thread.h>

SDL_Thread * SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data);

πŸ’… DESCRIPTION πŸ’…

so this one is a convenience function, meaning it's literally equivalent to calling SDL_CreateThreadWithProperties but with these properties already set for you:

  • SDL_PROP_THREAD_CREATE_ENTRY_FUNCTION_POINTER: fn
  • SDL_PROP_THREAD_CREATE_NAME_STRING: name
  • SDL_PROP_THREAD_CREATE_USERDATA_POINTER: data

and now the plot twist πŸ‘€ β€” this "function" is actually a macro that calls an internal function with two extra parameters that aren't listed here. they're hidden behind preprocessor macros, and they exist to support various C runtimes right at the point of the function call. so if you're writing language bindings and you're not using the C headers, you're gonna have to deal with that yourself. sorry babe, that's just the lore. 😭

but usually? apps should just call this function the same way on every platform and let the macros handle the details. no cap, that's the move. πŸ‘‘


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • fn β€” the SDL_ThreadFunction function that gets called in the new thread. the main character of your thread's whole storyline. ⭐
  • name β€” the name of the thread. give it a cute one. 🏷️
  • data β€” a pointer that gets passed to fn. πŸ“

🌈 RETURN VALUE 🌈

on success it returns an opaque pointer to the new thread object. if the new thread couldn't be created you get NULL instead β€” and in that case, go call SDL_GetError() for more info, she'll tell you what went wrong. πŸ™ˆ


πŸ”₯ THREAD SAFETY πŸ”₯

it is safe to call this function from any thread. yes, any. go off. πŸ’―


⭐ AVAILABILITY ⭐

this function is available since SDL 3.2.0. vintage-ish but make it fresh. ✨


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, bestie!! 🫢 this little love letter to SDL_CreateThread(3) came to you straight from Simple Directmedia Layer, SDL 3.4.18 β€” mwah, go forth and spawn threads responsibly πŸ’–πŸ§šπŸŒΈ

πŸ“¦ where this page comes from