mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-03-21 08:11:07 +01:00
We should wait for the state to stabilize before SDL_ShouldQuit() returns. For example: Thread A initializes and increments a use refcount Thread B skips initializing and increments the use refcount Thread B starts cleaning up and checks the use refcount Thread A starts cleaning up, returns because SDL_ShouldQuit() returns false (not initialized), not touching the use refcount Thread B returns because the use refcount isn't zero Now we have the state where the refcount is greater than one and both thread A and B have attempted to cleanup. With this change: Thread A initializes and increments a use refcount Thread B skips initializing and increments the use refcount Thread B starts cleaning up and decrements and checks the use refcount Thread A starts cleaning up, waits for thread B Thread B returns because the use refcount isn't zero Thread A continues and decrements and checks the use refcount, and finishes cleaning up because it has reached 0.