Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Audio Stream Mutex Issue

This thread is locked; no one can reply to it. rss feed Print
Audio Stream Mutex Issue
Todd Cope
Member #998
November 2000
avatar

I'm having an issue with my application freezing on an al_set_audio_stream_playing(..., false) call. Here are some details about how my program works.

I am attaching several audio streams to the default mixer and setting them to playing simultaneously. When I try to stop them using al_set_audio_stream_playing(..., false), the first stream successfully stops. Subsequent streams will occasionally lock the program up on that call.

To start the streams, I do something like this:

int start_streams(void)
{
    int i;
    for(i = 0; i < total_streams; i++)
    {
        if(al_attach_audio_stream_to_mixer(stream[i], al_get_default_mixer()))
        {
            if(!al_set_audio_stream_playing(stream[i], true))
            {
                return false;
            }
        }
    }
}

I stop the streams in a similar manner:

void stop_streams(void)
{
    int i;
    for(i = 0; i < total_streams; i++)
    {
        if(stream[i])
        {
            al_set_audio_stream_playing(stream[i], false);
            al_detach_audio_stream(stream[i]);
        }
    }
}

After some debugging I found that the lock up was happening inside al_set_audio_stream_playing(). It is attempting to lock a mutex that is already locked by the stream feeder thread and it never gets the lock.

I found that the issue is caused by al_detach_audio_stream() setting the first stream's mutex to NULL after the stream feeder thread has locked the stream's mutex but before it unlocks it. This causes the first stream's mutex to never get unlocked. Since all of the streams are sharing a single mutex, the second stream will never get the mutex lock because it is still locked.

SiegeLord
Member #7,827
October 2006
avatar

What do you think of this fix: https://github.com/liballeg/allegro5/pull/561

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Elias
Member #358
May 2000

I wonder if this explains some of the problems I had on Android when trying to stop audio streams while switched out. I ended up wanting to shut down the entire voice for battery saving reasons anyway in the end, but before that I think I had some lockups :/

--
"Either help out or stop whining" - Evert

Go to: