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:
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.
In
Pa_StopStream()
the DirectSound Host API waits for the streaming thread to signal aprocessingThreadCompleted
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.