Real time safe reading and writing of std::vector

Hi there!

Kinda of beginner here, still trying to get a handle on real time safe design method’s.

I can currently making a euclidean step sequencer, and I am having some difficulty finding a real time safe method of having the audio thread read from the array, when changes to the array may be made through gui thread.

Would it be best to create a vector of type atomic int, or is there a design practice where I wouldn’t have to worry about a data race between the gui and audio thread?

Any help would be so greatly appreciated. Thanks!

3 Likes

the audio thread usually doesn’t ask for information from the gui. i’d probably have the vector of int in the audioProcessor and a custom parameter component on the gui side with a vector of parameterAttachments so that these parameters update your vector next block

This kind of information is usually sent via a FIFO. The new pattern/vector is enqueued from the GUI thread and the audio thread will then pick it up from there.

If you haven’t already watched it, the realtime 101 from Fabian and Dave is a great lesson:

1 Like

Hi Daniel,

Thanks for link! I have watched that before, but watching it again solidified some of the concepts for me.

If anybody is having a similar issue in the future, I found this video very informative and quite specific to this problem.

Thanks for all the help guys! Makes life so much easier