Hello guys !
I have a couple of questions for the concurrency gurus of JUCE (Timur, Jules can you hear me ? )
I have written a few times some code for doing metering in plug-ins, but most of the time my implementations were ānaiveā to say the least, good enough in general but not clean enough I think to handle some potential concurrency issues. Iām trying to do something better right now, but I am not sure to know how to start⦠So here are my questions :
-
Iām a little confused by a few things I have seen in the example projects code and in Timurās presentations so Iād like to have some explanations. I know that the use of C++11 has come in the base code more and more often since JUCE 4 and is probably going to be an exclusive prerequisite for the use of JUCE in the future. The thing is, a few functions which exist in JUCE exist also in the std library, which I donāt know very well, such as the handling of threads, atomic variables, arrays, and have been updated a couple of times there but not that much in JUCE. So, Iād like to know if specialists recommend using std ones or JUCE ones. For threads for example, the use of them in JUCE seems simpler, but std:atomic seem better than JUCE::Atomic⦠I wonder also if some people use the JUCE:AbstractFIFO classā¦
-
Other question, I have an array which is filled in the audio thread, and I have a function which can be called as often as needed in the UI thread which reads some data from this array. Thatās my central problem and I have not found any good intel on it yet. How can I do it properly ? Until now, what I did was either ignoring all potential concurrency issues, which can be summarized here as having a not atomic read/write of the values in the array - or locking something, by putting a CriticalSection for the whole read/write functions, or in the templated declaration of the Array, which seems to be better but still imply the possibility of the audio thread locking in worst cases. How can I do better than that if itās not good enough without needing any lock-free external library, using only JUCE classes or C++11 / std functions ? Is it even possible ? Any thought ?
-
Last question : my calls to the read function which reads the content of the array is called every 50 ms for example. But if something bad happens on the UI thread, a lot of calls might be suspended until the CPU load allows the functions to work again properly. In a locking context, something like that is bad, so I was thinking about trying to use a kind of queue for making these calls, where extra calls might be removed, and maybe another thread to do it so the UI doesnāt freeze in worst cases because of the metering display. So, for example, if one call happens every 50 ms, everything is fine. But if 8-9 calls happen all at the same time for whatever the reason, 7-8 calls are dismissed, and only the last one is happening. So, I know that it is supposed to be some basic stuff, but Iād like to know how to do that properly. And again, can I do that with JUCE only ? Do I need some std classes ?
Iād really love to see more tutorials on this subject, because I have not seen yet some open source code for something which is supposed to be very simple, such as an audio meter, satisfactory enough for my limited understanding.
Thanks in advance !
Ivan