PortAudio / portaudio

PortAudio is a cross-platform, open-source C language library for real-time audio input and output.
Other
1.37k stars 286 forks source link

DirectSound Host API does not join its streaming thread correctly #926

Open dechamps opened 4 weeks ago

dechamps commented 4 weeks ago

In Pa_StopStream() the DirectSound Host API waits for the streaming thread to signal a processingThreadCompleted event and then assumes the thread is done when that happens:

https://github.com/PortAudio/portaudio/blob/18a606e1f928852bfc29639d9539ae74d37b5dee/src/hostapi/dsound/pa_win_ds.c#L3092

This is almost correct, but not quite. By the time the event is signaled, the thread is about to exit, but it has not exited yet.

This means that by the time Pa_StopStream() returns, the thread could still be running. If the application decides to unload the PortAudio DLL by that point, hilarity could ensue.

The correct way to do this is to wait on the thread handle itself, which is both safer and simpler.

I already have a fix for this in https://github.com/PortAudio/portaudio/pull/922.