I have a design question regarding the best way to use a thread to handle an occasional request from the Processor.
I have a need to sometimes perform an analysis of some audio that I’ve recorded from the processBlock() function, and I want to do this analysis on a background thread, and report back when that analysis has completed and certain data has been generated that the Processor can consume.
Would it be better to spawn this thread at startup, and let it run continuously, and then asking it, when needed, to perform this task, OR, would it be better to spawn it only when needed, and terminate it after posting its data and flagging the Processor that it is done?
I’m not worried about spawning it during processing; that is done when the user clicks a button to start the Analysis processing, and then the processBlock() function simply uses its current data until it has, at some point, consumed the data and is ready to process using that new data.
My concern is more about whether having that extra thread running at all times consumes resources that would be better used by other processes unless and until the user has asked for this Analysis phase to begin. Or whether it’s better, in general, to leave a background thread running and simply wake it up when needed to perform this task (which may take anywhere from a fraction of a second to a couple of seconds, and which will likely only be run once or twice in a particular session).