[alsa-devel] How to kill thread server_job() in snd_pcm_open()
I found that the thread server_job() can not be killed by using snd_pcm_close (). The code in snd_pcm_direct_server_discard() is disabled, and then it can not send signal to kill the thread. Why the code is disabled? Is there any bugs if I enable the code?
Rong-Jhe <r93922118 <at> ntu.edu.tw> writes:
I found that the thread server_job() can not be killed by using snd_pcm_close (). The code in snd_pcm_direct_server_discard() is disabled, and then it can not send signal to kill the thread. Why the code is disabled? Is there any bugs if I enable the code?
I have enabled the code in snd_pcm_direct_server_discard(), but it can not kill the thread of server_job(). The dmix->server_pid is wrong. In snd_pcm_direct_server_create(), the main thread uses fork() to establish a child thread and the child uses fork() to establish another child thread again. The main thread only keeps the pid of the first child thread, and the second child thread executes server_job(). Do to this, the main thread kills wrong pid. Further, the main thread uses waitpid() before keeping the pid of the first child thread, and the first child thread dies after establishing the second child thread. In this way, the pid kept in dmix->server_pid is useless. Why does the program need to use fork() two times?
On Mon, 14 Apr 2008, Rong-Jhe wrote:
Rong-Jhe <r93922118 <at> ntu.edu.tw> writes:
I found that the thread server_job() can not be killed by using snd_pcm_close (). The code in snd_pcm_direct_server_discard() is disabled, and then it can not send signal to kill the thread. Why the code is disabled? Is there any bugs if I enable the code?
I have enabled the code in snd_pcm_direct_server_discard(), but it can not kill the thread of server_job(). The dmix->server_pid is wrong. In snd_pcm_direct_server_create(), the main thread uses fork() to establish a child thread and the child uses fork() to establish another child thread again. The main thread only keeps the pid of the first child thread, and the second child thread executes server_job(). Do to this, the main thread kills wrong pid. Further, the main thread uses waitpid() before keeping the pid of the first child thread, and the first child thread dies after establishing the second child thread. In this way, the pid kept in dmix->server_pid is useless. Why does the program need to use fork() two times?
What you're trying to do? The server process will timeout (ends) itself when dmix clients are inactive.
Jaroslav
----- Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
What you're trying to do? The server process will timeout (ends) itself when dmix clients are inactive.
Jaroslav
Thanks for your response. My application uses two ways to play audio. One is using pcm interface in ALSA library, and another is using dsp file. My goal is to change the ways to play audio dynamically. The pcm in ALSA library also uses the audio device. There is only process can open the audio device at a time, so the audio device must be closed before changing the way. For example, if I open dsp file first and use write() to play audio, I need to close the dsp file and then open pcm to use snd_pcm_writei(). Similarly, if I open pcm first and use snd_pcm_writei(), I need to close the pcm and then open the dsp file immediately. Sometimes, when I change the way from using pcm to using dsp file, opening dsp file will get errors. I think it may be caused by the busy audio device. Is there any methods that can indicate whether the audio device used by pcm is free?
At Mon, 14 Apr 2008 07:47:02 +0000 (UTC), Rong-Jhe wrote:
What you're trying to do? The server process will timeout (ends) itself when dmix clients are inactive.
Jaroslav
Thanks for your response. My application uses two ways to play audio. One is using pcm interface in ALSA library, and another is using dsp file. My goal is to change the ways to play audio dynamically. The pcm in ALSA library also uses the audio device. There is only process can open the audio device at a time, so the audio device must be closed before changing the way. For example, if I open dsp file first and use write() to play audio, I need to close the dsp file and then open pcm to use snd_pcm_writei(). Similarly, if I open pcm first and use snd_pcm_writei(), I need to close the pcm and then open the dsp file immediately. Sometimes, when I change the way from using pcm to using dsp file, opening dsp file will get errors. I think it may be caused by the busy audio device. Is there any methods that can indicate whether the audio device used by pcm is free?
Not quite, AFAIK. The server process keeps opening the device, so it actually "uses" it.
BTW, with a recent version of ALSA drivers and libs, this server process won't be needed and won't be started at all. Think about updating the ALSA version, too.
Takashi
participants (3)
-
Jaroslav Kysela
-
Rong-Jhe
-
Takashi Iwai