[alsa-devel] Should snd_pcm_drop() interrupt snd_pcm_writei() call?
Hello,
I would like to know, how should snd_pcm_drop() call influence snd_pcm_writei() being simultaneously executed.
I expected, that after issuing snd_pcm_drop() (from another thread), the snd_pcm_write*() in progress should be terminated almost immediately with some return value (error or short write). According to my observation, this seem to work on ALSA lib & driver 1.0.14rc3, snd_ali5451.
However, it never or almost never works on another machine with ALSA lib 1.0.16 (Debian package libasound2 [1.0.16-2], driver unknown, sorry). There, the snd_pcm_write*() _never_returns_ after snd_pcm_drop(), and remain stuck forever.
I would like to ask you, which behaviour of snd_pcm_drop/snd_pcm_write* is the correct one. I suppose the snd_pcm_write*() should be interrupted, otherwise, an extra thread would be needed in many applications. However, I don't know, why does not it work in the later version of ALSA.
I have not found the answer in Doxygen, and since I am real ALSA newbie, I gave up reading ALSA source, especially because I have seen different behaviour among two different versions. Excuse my impatience.
Thank you for a clarification. Best regards, Marek.
I would like to know, how should snd_pcm_drop() call influence snd_pcm_writei() being simultaneously executed.
I expected, that after issuing snd_pcm_drop() (from another thread), the snd_pcm_write*() in progress should be terminated almost immediately with some return value (error or short write). (..)
Today, Jara Kysela told me, that calling pcm functions from multiple threads is not recommended practice.
This explains the problems I encountered. I missed the information, that these functions are not meant to be thread-safe.
Best regards, Marek.
At Fri, 15 May 2009 15:57:49 +0200 (CEST), Marek Peca wrote:
I would like to know, how should snd_pcm_drop() call influence snd_pcm_writei() being simultaneously executed.
I expected, that after issuing snd_pcm_drop() (from another thread), the snd_pcm_write*() in progress should be terminated almost immediately with some return value (error or short write). (..)
Today, Jara Kysela told me, that calling pcm functions from multiple threads is not recommended practice.
This explains the problems I encountered. I missed the information, that these functions are not meant to be thread-safe.
Although it's not recommended, the behavior you described sounds strange. Could you check whether this still happens with the very latest alsa-lib version? Also I guess this depends on the plugin to be used, e.g. dmix or not.
Takashi
This explains the problems I encountered. I missed the information, that these functions are not meant to be thread-safe.
Although it's not recommended, the behavior you described sounds strange. Could you check whether this still happens with the very latest alsa-lib version?
Yes, we will try to, but I need some cooperation with colleague, so it will take some time.
Also I guess this depends on the plugin to be used, e.g. dmix or not.
I see. Please, can you tell me, whether I should rewrite my program to purely single-thread acces to snd_pcm_write & snd_pcm_drop, or should I expect, that in ALSA (with proper plugin) it should work in correct releases?
Thank you for your answers, Marek.
At Fri, 15 May 2009 16:28:06 +0200 (CEST), Marek Peca wrote:
This explains the problems I encountered. I missed the information, that these functions are not meant to be thread-safe.
Although it's not recommended, the behavior you described sounds strange. Could you check whether this still happens with the very latest alsa-lib version?
Yes, we will try to, but I need some cooperation with colleague, so it will take some time.
Also I guess this depends on the plugin to be used, e.g. dmix or not.
I see. Please, can you tell me, whether I should rewrite my program to purely single-thread acces to snd_pcm_write & snd_pcm_drop, or should I expect, that in ALSA (with proper plugin) it should work in correct releases?
A safer option is the single thread access if you want your app to support many different systems including old ALSA. In addition, you could add a different approach depending on the version, e.g. by checking in configure script.
Anyway, checking with the latest version is helpful for us ;)
thanks,
Takashi
A safer option is the single thread access if you want your app to support many different systems including old ALSA. In addition, you could add a different approach depending on the version, e.g. by checking in configure script.
Well, I must think about it. It seems, that our app will be closely distributed with well-defined and recent OS/ALSA version. It may be useful for me to know, whether this particular two-thread access to these functions should be supported in present and future.
Anyway, checking with the latest version is helpful for us ;)
Yes, I will try to check it against new ALSA version and I will tell you any interesting observations.
Many thanks, Marek.
participants (2)
-
Marek Peca
-
Takashi Iwai