Hello.
I noticed for quite a while now that sometimes my SDL application which deals with audio hangs completely during start up. I then built it with thread sanitizers and indeed there is a potential for a deadlock. This is what I've got.
I'm not familiar with the code at all, so all I figured out for now is that M0 is the device lock, while M1 is some other mutex and there are the main thread and a secondary Pipewire thread at play.
static void output_callback(void *data)
{
SDL_AudioDevice *device = (SDL_AudioDevice *) data;
// this callback can fire in a background thread during OpenDevice, while we're still blocking
// _with the device lock_ until the stream is ready, causing a deadlock. Write silence in this case.
if (device->hidden->stream_init_status != PW_READY_FLAG_ALL_BITS) {
int bufsize = 0;
Uint8 *buf = PIPEWIRE_GetDeviceBuf(device, &bufsize);
if (buf && bufsize) {
SDL_memset(buf, device->silence_value, bufsize);
}
PIPEWIRE_PlayDevice(device, buf, bufsize);
return;
}
SDL_PlaybackAudioThreadIterate(device);
}
Also reading this, it looks like the issue is known, but not high priority for now.
So I would like to gently make you reconsider this issue some time in the future. It did end up in deadlock a handful of times for me already.
Hello.
I noticed for quite a while now that sometimes my SDL application which deals with audio hangs completely during start up. I then built it with thread sanitizers and indeed there is a potential for a deadlock. This is what I've got.
I'm not familiar with the code at all, so all I figured out for now is that
M0is the device lock, whileM1is some other mutex and there are the main thread and a secondary Pipewire thread at play.Also reading this, it looks like the issue is known, but not high priority for now.
So I would like to gently make you reconsider this issue some time in the future. It did end up in deadlock a handful of times for me already.