Re: [AD] Deadlock in KCM audio

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 2010-10-24, Trent Gamblin <trent@xxxxxxxxxx> wrote:
> I've experienced a number of "issues" with KCM audio, and tried to debug
> them to no avail. I can't get my head around what's happening in that code.
> Anyway, I post in hopes that someone may be able to help with a specific issue
> of deadlock. My game tries to play an ogg:
> 
> void playMusic(std::string name, bool setLoopStart, unsigned int loopStart)
> {
> 	if (!sound_inited) return;
> 
> 	if (musicName == name)
> 		return;
> 	
> 	musicName = name;
> 
> 	if (music) {
> 		al_detach_audio_stream(music);
> 		al_set_audio_stream_playing(music, false);
> 		al_destroy_audio_stream(music);
> 	}
> 
> 	if (name == "") {
> 		music = 0;
> 		return;
> 	}
> 
> 	music = al_load_audio_stream(getResource("music/%s", name.c_str()).c_str(), 4,
> 		1024*2);
> 	
> 	if (!music) {
> 		return;
> 	}
> 	
> 	al_set_audio_stream_playmode(music, ALLEGRO_PLAYMODE_LOOP);
> 
> 	if (setLoopStart) {
> 		al_set_audio_stream_loop_secs(music, loopStart/1000.0,
> 			al_get_audio_stream_length_secs(music));
> 	}
> 
> 	al_attach_audio_stream_to_mixer(music, al_get_default_mixer());
> 
> 	setMusicVolume(1);
> }
> 
> In some rare occurances, it deadlocks on line 880 in kcm_mixer.c. This is on OS X.
> I spent the past few weekends testing the same code on Linux and never ran into
> a deadlock once. However, the code is shared between both platforms. I also tested
> very heavily on iPhone and thought my KCM woes were behind me. Any help, such as
> advice on where to look for the coinciding lock would be MUCH appreciated.

It's going to be pretty hard finding the problem just by reading the
code.  Can you not run under gdb and do a backtrace on all the running
threads?  (info threads; thread N; bt)

Otherwise you might have to start logging each mutex lock/unlock in the
audio addon.

We should probably move to more coarse-grained locking in the future to
reduce these kinds of problems.

Peter




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/