libsdl-org / SDL

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

cpuinfo APIs aren't thread-safe #11322

Open icculus opened 4 weeks ago

icculus commented 4 weeks 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 4 weeks ago

That seems like a reasonable change for the future.

madebr commented 4 weeks 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 4 weeks ago

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