I cannot find any information about the thread-safety of the waveOut API.
After i creating new waveOut handle, i have those threads:
Thread 1: Buffers handling. Uses those API functions:
- waveOutPrepareHeader
- waveOutWrite
- waveOutUnprepareHeader
Thread 2: Gui, Controller thread. Uses those API functions:
- waveOutPause
- waveOutRestart
- waveOutReset
- waveOutBreakLoop
Those two threads are running while using concurrently the same waveOut handle. In my tests, i didn't saw any problem with the functionality, but it doesn't mean that it safe.
Is this architecture thread-safe? Is there any documentation about the thread safety of the waveOut API? Any other suggestions about the waveOut API thread-safety?
thanks.
In general the waveOut API should be thread-safe. Because usually a waveOutOpen() creates its own thread, and all waveOut* functions send messages to that thread. But I can not give you a proof...
However, you can change your application to make it safe in any case:
example 1
If you want to be 100% sure, you could just grab a windows message (WM_USER+0), and call
PostThreadMessage( WM_USER+0, dwBufferThreadId, MY_CTL_PAUSE,0 )
and then upon receiving that message in your buffering thread, you callwaveOutPause()
there. Windows message queues save you some work on writing your own message queues ;-)