#25 Fix for deadlock in SDL sound code

open
None
8
2006-08-25
2005-12-16
No

This is a fix for bug #1189126:
http://sourceforge.net/tracker/index.php?func=detail&aid=1189126&group_id=63889&atid=505529

There is an opportunity for deadlock to occur in the
SDL sound code, causing random freezing. Here is an
example (sdlSoundLen starts off being < 4096):

--- audio thread (soundCallback)
if(!speedup && !throttle) {
while(sdlSoundLen < 2048*2) {
--- main thread (systemWriteDataToSoundBuffer)
sdlSoundLen = 2048*2;
SDL_CondSignal(cond);
--- audio thread
if(emulating)
SDL_CondWait(cond, mutex);
--- main thread
cont = true;
if(!speedup && !throttle) {
while(cont) {
SDL_mutexP(mutex);
if(sdlSoundLen < 2048*2)
cont = false;
SDL_mutexV(mutex);
}

At this point, the main thread has already signalled
the audio thread but the audio threadwas not listening.
So, the main thread waits for the buffer to be dumped,
constantly checking sdlSoundLen, while the audio thread
waits to be signalled.

My patch uses a cleaner implementation using semaphores
instead of conditional waiting. This also means that
VBA no longer uses 100% CPU due to busy waiting such as
the last loop in the example.

Discussion

  • Anonymous - 2005-12-16

    patch against current CVS

     
    Attachments
  • Anonymous - 2005-12-16
    • priority: 5 --> 8
     
  • Pokemonhacker

    Pokemonhacker - 2006-05-08

    Logged In: YES
    user_id=785003

    Patch applied. Thanks !!!

     
  • Pokemonhacker

    Pokemonhacker - 2006-05-08
    • status: open --> closed
     
  • Spacy

    Spacy - 2006-08-25
    • status: closed --> open
     
  • Spacy

    Spacy - 2006-08-25

    Logged In: YES
    user_id=1355343

    There is still a freeze when closing the SDL window udner
    windows. It freezes exactly when trying to execute
    SDL_CloseAudio (); in function void systemSoundShutdown().

    Unfortunately I do not understand what is going on there.

     
  • Spacy

    Spacy - 2006-08-25
    • assigned_to: nobody --> kxu
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks