Skip to content

Commit

Permalink
Make sure timers are initialized before any threads start
Browse files Browse the repository at this point in the history
This prevents race conditions and divide by zero if multiple threads start using the time functions simultaneously.
  • Loading branch information
slouken committed Jul 12, 2024
1 parent b13dcf2 commit b378bc5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/thread/SDL_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "SDL_systhread.h"
#include "SDL_hints.h"
#include "../SDL_error_c.h"
#include "../timer/SDL_timer_c.h"

/* The storage is local to the thread, but the IDs are global for the process */

Expand Down Expand Up @@ -371,6 +372,10 @@ SDL_Thread *SDL_CreateThreadWithStackSize(int(SDLCALL *fn)(void *),

SDL_InitTLSData();

#ifndef SDL_TIMERS_DISABLED
SDL_TicksInit();
#endif

/* Allocate memory for the thread info structure */
thread = (SDL_Thread *)SDL_calloc(1, sizeof(*thread));
if (!thread) {
Expand Down

0 comments on commit b378bc5

Please sign in to comment.