<div dir="ltr"><div>Since few weeks, I work on a plugin that dynamically loads Pure Data patches, creates a GUI depending on the graphical objects of the patch and retrieves their parameters to link them with the automation system of the host. Everything works fine, but I had some issues to manage several PD instances with multiple threads (pdlib doesn't manage multiple instances). </div><div><br></div><div>I made my own implementation that solved the problem and I found 2 small things that could really improve the development of applications with Pure Data.</div><div><br></div><div><div>I try to explain :</div><div>The main problem isn't the loading of patches that can be managed using locks but  running the pacthes in parallele. For what I've seen, attack ships on fire off the shoulder of Orion... sorry I digress. For what I've seen, there are only 2 things that cause problems : the dsp chains and the clocks. Here my solutions :</div><div><br></div><div>1 - "t_pdinstance*" in the prototypes of the functions "sched_tick()" and  "dsp_tick()". This way, we don't need to call "pd_setinstance" at each dsp tick so it is thread safe.</div><div>(we could have something like "pdinstance_sched_tick(t_pdinstance* x)" and "pdinstance_dsp_tick(t_pdinstance* x)" to ensure the good working of previous applications)</div><div><br></div><div>2 -  "t_pdinstance*" in the structure of the clock. All the clock_new functions seem to be called in the "creation" methods of the objects. If when we load a patch and we create objects, "pd_this" is well defined, we can initialize the reference "t_pdinstance*" of the clock with "pd_this" and later when we'll call "clock_set" the clock will use its reference instead of "pd_this". In this case, imagine that we send a  bang to a [delay] in one instance during the loading of a pacth in another instance, even if "pd_this" is not the good one, the clock will be added to the clocks list of its instance.</div></div><div><br></div><div>For the moment, I don't use this updates (I manage everything with locks) because I want to be compatible with future versions of Pure Data. But if you think that can be a good thing, I can submit the code. Can I use GitHub for this ?<br></div><div><br></div><div>Cheers</div></div>