I’m trying to compile SDL not using autotools and I’m not sure about the
threads usage in SDL2.
Are you rolling your own build system here, or using CMake, or…?
I’ve been told that SDL2 on Windows actually compiles cleanly out of the
box by just pushing the .c files through the compiler as-is, but I can’t
confirm that. On Unix/Linux systems (places that would need pthreads), I
can’t imagine rolling a stable build system for all the things our build
systems do is much fun.
First, I would prefer to use c11 threads, so I would like to not permit
the use of SDL threads at all, but I’m not sure how to do this, when
using SDL_THREADS_DISABLE I get this message: “SDL not built with thread
support” and SDL_init fails. So, I get to the second issue:
That specific error is probably a bug in our build system, because it’s
extremely rare that someone would build SDL2 without thread support.
Is there a reason you want no SDL threads at all? At a minimum, it’ll
break the audio subsystem and a few other things, even if we fix the
SDL_Init() bug you mentioned.
Trying to compile with threads but using only generic/* and not
pthreads/* I got a infinite recursion between CreateMutex and
CreateSemaphore.
The generic code is meant to be used when the system doesn’t provide all
the facilities we’d expect, so we build off the ones they do provide.
I would like to know exactly what is needed in terms o threads to get
SDL2 working (generics + pthreads?), so why have the option to not use
pthreads? And how to get it working?
Not having pthreads probably goes back a long long way to when threads
were a new thing in Linux, or perhaps for crusty Unix variants that
didn’t support them at all. It’s not really surprising to me that
changing these defaults breaks things in SDL2, as you’re trying to flip
a switch that hasn’t been flipped in over a decade.
I would say: let it build with full pthread support, and if you’d rather
your app uses c11 threads, then just use them instead in your app. The
handful of things that use a thread internally in SDL will still use SDL
threads internally, but everything will just be pthreads under the hood
anyhow.
(although a c11 thread backend in SDL, as a fallback for systems without
pthreads, etc, might be interesting, but I’m not sure what platforms it
would cover that we don’t already have, at least in current times.)
–ryan.