ALSA does not generate threads for you like this. I was referring to your application's audio thread, assuming that your app is indeed multithreaded.
The duration probably varies because the call to snd_pcm_writei() will block until there is enough space in the ALSA ringbuffer to receive your data.
Lee
I found that there will be a thread generated after calling snd_pcm_open(). I use command 'ps' to check it. Due to this I guess snd_pcm_writei() only put the data into the buffer of the thread 'pcm'.
This thread then schedules of mixes the audio data, and put it into the buffer of ALSA driver. ALSA ringbuffer only belongs to ALSA library, and ALSA driver uses anoother buffer in kernel. Thus, there must be a thread that can put the data in ALSA ringbuffer into the buffer of ALSA driver.