ZSNES board Forum Index ZSNES board
ZSNES and other SNES related stuff
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Linux Sound Bug [libao] [patch]

 
Post new topic   Reply to topic    ZSNES board Forum Index -> Bug Reports/Feature Requests
View previous topic :: View next topic  
Author Message
mspang
New Member


Joined: 31 Dec 2007
Posts: 1

PostPosted: Mon Dec 31, 2007 11:44 pm    Post subject: Linux Sound Bug [libao] [patch] Reply with quote

In src/linux/audio.c, pthread_create() is called before pthread_mutex_init() and pthread_cond_init(). The created thread then tries to lock the (possibly uninitialized) mutex.

If the thread gets to pthread_mutex_lock() before the mutex is initialized, the sound thread deadlocks and there is no sound. This affects libao drivers, not SDL, but almost always occurs on my dual core machine (90% or more of the time).

The mutex and condition need to be initialized before creating the thread. Patch:

Code:
diff -ur zsnes-1.510/src/linux/audio.c zsnes-1.510-new/src/linux/audio.c
--- zsnes-1.510/src/linux/audio.c   2007-01-09 20:19:12.000000000 -0500
+++ zsnes-1.510-new/src/linux/audio.c   2007-12-30 20:33:07.000000000 -0500
@@ -177,11 +177,7 @@
   }
   else
   {
-    if (pthread_create(&audio_thread, 0, SoundThread_ao, 0))
-    {
-      puts("pthread_create() failed.");
-    }
-    else if (pthread_mutex_init(&audio_mutex, 0))
+    if (pthread_mutex_init(&audio_mutex, 0))
     {
       puts("pthread_mutex_init() failed.");
     }
@@ -189,6 +185,10 @@
     {
       puts("pthread_cond_init() failed.");
     }
+    else if (pthread_create(&audio_thread, 0, SoundThread_ao, 0))
+    {
+      puts("pthread_create() failed.");
+    }
     InitSampleControl();
   }


Last edited by mspang on Wed Jan 02, 2008 5:14 am; edited 1 time in total
Back to top
View user's profile Send private message
Nach
ZSNES Developer
ZSNES Developer


Joined: 27 Jul 2004
Posts: 4588
Location: Solar powered park bench

PostPosted: Tue Jan 01, 2008 12:40 am    Post subject: Reply with quote

Thanks.
_________________
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    ZSNES board Forum Index -> Bug Reports/Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group