Multithreaded plugins


#1

 

Hey Jules -

 

Still investigating this, but I'm getting some issues with background threads in plugins.

They all work fine, but don't seem to deallocate properly?  So, if I run a plugin, then destroy it, then create it again - the background threads are all screwed up (refuse to launch, or believe that run() is a pure virtual method, or just crash the host).  I assume this means that those threads are sticking around in static memory somehow after the dealloc?

Not really sure what's going on, but thought you might have some wisdom about additional challenges of threads in plugins.

I should note, that I have a standalone version that works perfectly - so this seems to be just certain threads in (VST, mac) plugins.

I even (sometimes) have this issue with a simple FileTreeComponent.  Anyway - maybe I am just doing something silly, but I can't see what.

 


#2

 

Actually, digging a bit deeper .... the problem is with String deallocation ... maybe?

This is happening when I try to construct a File(absolutPath).  

Again ... it works fine ... until I delete the plugin once, then create it again.  There are no apparent Leaks .... but something is getting screwed up.

 

 


#3

Looks more like a dangling pointer to me than a threading issue. Probably not the string class that's having an issue, more likely the object that contains the string that's been deleted or broken.


#4

 

 

Yeah, that's what I came to, also. 

Just can't figure it out, because that pointer should be fine. 

gah ..... !


#5

The question is where was this object created (in which thread context).
Since plugins run in the application’s process, when you deallocate them, the threads they spawned do not automatically get deallocated or terminated at the same time; that’s something you need to take care of.
If a long-running (read: unterminated) thread still owns the object in question, this can cause all sorts of funny behaviour.
Thus, as a plugin developer, it is absolutely necessary to clean up thoroughly after yourself. If you don’t, all sorts of strange, unpredictable things can happen, especially if you’ve spawned threads.


#6

 

Good summup, all great advice.

 

I was barking up the rwong tree however - as the thread and File in question were being used in a SampleSound, and I didn't realize how often that was getting allocated/deallocated.  So, the sound was resetting, and destroying the File object (though it was used elsewhere in the UI).

 

duh.

 

 


#7

Well, I guess finding that bug took some real effort.
Glad you found the solution to your problem and shared it with us so everybody can learn the lesson.