SDL_RunOnMainThread(3)
π SDL_RunOnMainThread(3) π
okay bestie, this one lives in the SDL3 FUNCTIONS section of the manual and it's genuinely so useful, come sit with me π«Ά
β¨ NAME β¨
SDL_RunOnMainThread β call a function on the main thread during event processing. that's the whole vibe. π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_init.h>
bool SDL_RunOnMainThread(SDL_MainThreadCallback callback, void *userdata, bool wait_complete);
π DESCRIPTION π
okay so here's the tea, and it's actually really simple:
- if you call this on the main thread, the
callbackruns immediately. like, right now, no queue, no waiting, just go πβοΈ - if you call this on another thread, the
callbackgets queued for execution on the main thread during event processing. so it'll happen, just on the main thread's schedule, not yours β¨
β οΈ be careful of deadlocks when you use this, fr fr. you should not have the main thread wait for the current thread while this function is being called withwait_completeset totrue. that's a deadlock recipe and we do NOT do that in this house π
π FUNCTION PARAMETERS π
callbackβ the callback to call on the main thread. this is the thing you want to happen, main-character edition πuserdataβ a pointer that is passed tocallback. your lil goodie bag of stuff πwait_completeβtrueto wait for the callback to complete,falseto return immediately. blocking mode or girlboss mode, your call π
β RETURN VALUE β
returns true on success or false on failure β and bestie, if it fails, call SDL_GetError() for more information. she will tell you what went wrong, no cap π
π¦ THREAD SAFETY π¦
it is safe to call this function from any thread. periodt. πΈ
π§ AVAILABILITY π§
this function is available since SDL 3.2.0. so if you're on something older... upgrade, babe π
π₯ SEE ALSO π₯
Simple Directmedia Layer π«Ά SDL 3.4.18 β that's the source and version right there, mwah, hope this helped bestie, go slay your main thread β¨ππ
π¦ 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