[alsa-devel] [PATCH 0/2] Fix thread safety issues

Jérôme Forissier jerome at taodyne.com
Wed Jan 30 19:13:54 CET 2013


On 30 janv. 2013, at 17:03, Takashi Iwai wrote:

> At Wed, 30 Jan 2013 16:22:15 +0100,
> Jerome Forissier wrote:
>> 
>> This is a set of two patches to fix thread safety issues I found when running
>> a video application over ALSA. The application uses LibVLC to play several
>> videos simultaneously. LibVLC calls snd_pcm_open() and snd_device_name_hint()
>> from multiple threads, without locking--which is allowed according to
>> http://www.alsa-project.org/main/index.php/SMP_Design.
> 
> The fix for snd_pcm_direct_parse_open_conf() looks good.  I'm going to
> apply this now.

Good, thank you :)

> snd_device_name_hint() should use snd_config_update_r() and pass the
> local config space to others instead of snd_config.


I tried following this path, but there is a problem: try_config() calls snd_lib_error_set_handler() so I fail to see how we can make this code reentrant.
In fact, the random errors I've seen when running my multi-threaded test were probably just a side-effect of fiddling with the global error handler from multiple threads. Probably harmless, but still it makes snd_device_name_hint() not thread-safe, strictly speaking.

Any suggestion? Should I consider moving snd_lib_error to thread-local storage?

Thanks.

-- 
Jerome



More information about the Alsa-devel mailing list