-
Notifications
You must be signed in to change notification settings - Fork 64
SDL threads should be enabled #148
Comments
Upstream made it possible to enable threads for configure/cmake in libsdl-org/SDL@a81fe27. When building through ports it should be automatic SDL2/include/SDL_config_emscripten.h Lines 137 to 139 in 6a72595
(+ stuff in https://github.com/emscripten-core/emscripten/blob/main/tools/ports/sdl2.py to build the right files) |
So why am I not seeing any of these changes here? |
We're a few releases behind upstream... and that commit hasn't made it into a release yet. Also, if you're using this with |
I updated Emscripten to 2.0.25 to pick up these changes. Big mistake! My app now results in the browser becoming unresponsive on loading (tested in Chrome) with no messages in the console to give me a clue why. My download also became a lot bigger because of sdl2_ttf pulling in harfbuzz as a dependency, which I don't want. So do you happen to know which is the earliest release that will give me the SDL2 threads update? |
Initial thread support was added back in 1.38.31(emscripten-core/emscripten@f185044), last update I can see was in 1.38.39 (emscripten-core/emscripten@5e5e79d). Hmm, looking at those changes I don't see the |
I'm currently building with 2.0.5 and SDL2 threads are definitely not enabled. Looks like if I want that but not the SDL2_ttf Harfbuzz bloat (first in 2.0.13) I'm not going to be able to use -s USE_SDL=2 -s USE_SDL_TTF=2. For the moment I'm coping with the non-thread SDL2 by adding my own thread-protection mutex. Messy, but it works. |
I think pre 2.0.22 emscripten would need something like this: diff --git a/tools/ports/sdl2.py b/tools/ports/sdl2.py
index 349d8ba9e..c6bd4512e 100644
--- a/tools/ports/sdl2.py
+++ b/tools/ports/sdl2.py
@@ -293,7 +293,9 @@ sdl_config_h = r'''/* include/SDL_config.h. Generated from SDL_config.h.in by c
#define SDL_HAPTIC_DISABLED 1
/* #undef SDL_LOADSO_DISABLED */
/* #undef SDL_RENDER_DISABLED */
+#ifndef __EMSCRIPTEN_PTHREADS__
#define SDL_THREADS_DISABLED 1
+#endif
/* #undef SDL_TIMERS_DISABLED */
/* #undef SDL_VIDEO_DISABLED */
/* #undef SDL_POWER_DISABLED */
@@ -358,7 +360,9 @@ sdl_config_h = r'''/* include/SDL_config.h. Generated from SDL_config.h.in by c
/* #undef SDL_LOADSO_WINDOWS */
/* Enable various threading systems */
-/* #undef SDL_THREAD_PTHREAD */
+#ifdef __EMSCRIPTEN_PTHREADS__
+#define SDL_THREAD_PTHREAD 1
+#endif
/* #undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX */
/* #undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP */
/* #undef SDL_THREAD_WINDOWS */
(I guess the Harfbuzz dependency could be made optional as it's optional in SDL2_ttf itself and SDL2_image has a similar thing with llibpng/jpeg. Haven't looked much at the ports handling of SDL2_ttf though.) |
That's helpful, I might try it.
Making it optional would be great (I'm surprised it wasn't done that way). |
Editing sdl2.py as suggested (I think I did it correctly) is giving this:
|
That error resulted from an incomplete build (I'd done emcc --clear-ports and deleted all my object files, but it needed the .html file to be deleted as well for some reason). However building with threads enabled just gives me a version which freezes the browser on loading again (not even clicking on Chrome's close button works). So something about SDL2's threads system is blocking startup. |
Hmm, did get a browser hang with a minimal thread test... Seems SDL waits for the thread to start after creating it and gets stuck as it's never starts. Setting |
Interesting. I must admit I'm very tempted to stick with what I have, because it works perfectly (as far as I can tell). That is, I'm configuring SDL2 without threads, but using them anyway, with my own Mutex to prevent concurrent access to the events queue. I expect I am risking some thread issues arising, but so far I've not noticed anything. |
SDL threads are disabled, e.g. by set(SDL_THREADS_DISABLED 1) in CMakeLists.txt, even when WebAssembly threads are enabled with -s USE_PTHREADS=1. Specifically this means that the SDL_EventQ.lock mutex is inactive, which breaks applications which push events on one thread and read them on another.
The text was updated successfully, but these errors were encountered: