Author Topic: Best practice to handle changes in callback function (with blocking call?)  (Read 151 times)

Gazoo

  • Posts: 47
Hi BASS'ers,

I'm using a decoding channel attached to the NoSound Hardware on the Windows platform, upon which two split channels have been created and associated with real audio hardware. A far more in-depth description of that can be found here: https://www.un4seen.com/forum/?topic=17691.0

The callback function occasionally enters a critical section, using data which is occasionally altered in the main thread. I've experimented a bit with pausing the split channels, resetting them, and starting them again. I had initially thought that 'BASS_ChannelPause' might be blocking and only resume once the callback function had ended. I've now come to understand that this is not the case. It is possible for the callback function to be in mid-execution when 'BASS_ChannelPause' is called. The outcome can be that the 'BASS_ChannelPause' call returns immediately even though the callback function has yet to finish.

So my question is if I will need to use some mutex on my own in the callback function to ensure a critical section is only entered once, or is there another preferred method of stopping and starting the callback function to avoid synchronization problems?

Regards,
Lasse

Ian @ un4seen

  • Administrator
  • Posts: 20433
Please confirm what "the callback function" is, eg. is it a BASS callback function, and if so, what type? Are you trying to prevent it running multiple times simultaneously? If so, you could indeed put a critical section in there.

If you want to block a BASS channel from doing any processing (eg. decoding), you can use BASS_ChannelLock to do so.