[SDL] race condition in SDL_ThreadedTimerCheck?

Clifford T. Matthews ctm at ardi.com
Tue Jan 4 11:13:20 PST 2005


>>>>> "Sam" == Sam Lantinga <slouken at devolution.com> writes:

    Sam> Hi Cliff!
    >> I have an application that uses SDL_SetTimer that dies on
    >> Hyperthreaded P4s running Windows XP.  Looking at
    >> SDL_ThreadedTimerCheck, I see this code:

    >> SDL_mutexV(SDL_timer_mutex); ms = t->cb(t->interval, t->param);
    >> SDL_mutexP(SDL_timer_mutex);

    >> But without SDL_timer_mutex being held, can't the memory
    >> pointed to by t be freed?  Shouldn't a copy of *t be made on
    >> the stack before the lock is released and then that copy's cb,
    >> interval and param field be used?

    Sam> Yep, thanks for catching this.

You're welcome.  The problem actually showed up about a year ago and
I've only now had time to track it down.  I thought it was an Executor
bug until I peered into the timer code.  There still may be Executor
timer bugs, but there are some problems with the SDL timer code that
need to be cleaned up.

    Sam> Please try the attached file, to see if it's fixed.

That doesn't fix it.

I have a fix I've been testing that definitely improves things.  I
think I saw one mystery crash with my new fix in though, so I'm
reluctant to send anything out until I investigate further.

Other problems in the timer code, I beleive, include not setting
list_changed to SDL_TRUE if the callback returns 0, and the setting of
list_changed to SDL_FALSE unconditionally in the loop.


--Cliff Matthews <ctm at ardi.com>
+1 505 363 5754 Cell





More information about the SDL mailing list