allegro5
allegro5 copied to clipboard
Deadlock in al_uninstall_system on audio stream destructor
If there's a leaked audio stream when Allegro quits, the application hangs due to a deadlock in audio stream destructor.
Minimal example of a problem:
#include <allegro5/allegro.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>
int main(int argc, char **argv) {
al_init();
al_install_audio();
al_init_acodec_addon();
ALLEGRO_VOICE *voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2);
ALLEGRO_MIXER *mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2);
al_attach_mixer_to_voice(mixer, voice);
ALLEGRO_AUDIO_STREAM *stream = al_load_audio_stream("test.wav", 4, 1024);
al_attach_audio_stream_to_mixer(stream, mixer);
al_set_audio_stream_playing(stream, true);
al_rest(1.0);
//al_destroy_audio_stream(stream);
al_destroy_mixer(mixer);
al_destroy_voice(voice);
return 0;
}
Thread 1 "main" received signal SIGINT, Interrupt.
0x00007f8711e22c59 in pthread_cond_destroy@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
(gdb) bt
#0 0x00007f8711e22c59 in pthread_cond_destroy@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
#1 0x00007f8712ba3065 in _al_cond_destroy (cond=0x7f86f0000940) at ../include/allegro5/platform/aintuthr.h:76
#2 0x00007f8712b987d7 in al_destroy_event_queue (queue=0x7f86f00008c0) at ../src/events.c:138
#3 0x00007f8712b97e0f in _al_run_destructors (dtors=0x100225db0) at ../src/dtor.c:120
#4 0x00007f8712bad7d3 in al_uninstall_system () at ../src/system.c:311
#5 0x00007f871237c538 in __run_exit_handlers () from /usr/lib/libc.so.6
#6 0x00007f871237c58a in exit () from /usr/lib/libc.so.6
#7 0x00007f87123664d1 in __libc_start_main () from /usr/lib/libc.so.6
#8 0x0000000100000aaa in _start ()
When al_destroy_audio_stream is uncommented, audio plays for a second, then stops and program quits. When it's commented out, audio plays for a second, then stops, but the program hangs and needs to be manually killed.
Tested on GNU/Linux (Arch)
Unlike the al_shutdown_*() methods for other addons, there is no al_shutdown_acodec_addon() for the audio codec addon. It could be related.
Also, the addon codec addon even remains "initialized" via al_is_acodec_addon_initialied even after system shutdown and uninstall audio.