libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.85k stars 1.83k forks source link

cpuinfo APIs aren't thread-safe #11322

Open icculus opened 1 week ago

icculus commented 1 week ago

This is not a big deal, since probably no one will get bit by this, but all of the CPU info functions race to initialize on the first call.

It might be worth detecting all the CPU stuff in a single function, wrapped in an SDL_ShouldInit(), and having each of the entry points call that function to initialize on-demand safely and simply return the piece of data they care about...and then just never deinitialize the SDL_InitState, since the CPUs won't change.

slouken commented 1 week ago

That seems like a reasonable change for the future.

madebr commented 1 week ago

I'd like to only make a small point that there is SDL_CPU_FEATURE_MASK hint that can change after a SDL_Quit, and before a second SDL_Init. Or is this a don't care?

icculus commented 1 week ago

We can redetect after a quit, it's not a dealbreaker to do so.