AudioProcessor::getListenerLocked Usefulness?


As I mentioned in another post I’m looking at ways to optomise the plugin parameter system and came across a hotspot in getListenerLocked.

I can sort of understand that this lock protects access to the listener list so two threads don’t add and remove listeners at the same time but the lock doesn’t protect access to the listener’s use.
For example, in AudioProcessor::sendParamChangeMessageToListeners

for (int i = listeners.size(); --i >= 0;)
    if (auto* l = getListenerLocked (i))
        l->audioProcessorParameterChanged (this, parameterIndex, newValue);

What if the listener is removed and deleted during the audioProcessorParameterChanged call?

I’m not sure what the conventions are for adding/removing listeners and getting their callbacks but I would have thought these were message thread only or at least that you can’t expect listeners to be called when the plugin is unprepared and you can only add/remove listeners at this time?