[PD-dev] Improving PD for multi-instances and multithreading.

Pierre Guillot guillotpierre6 at gmail.com
Thu Sep 10 11:22:47 CEST 2015


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).

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.

I try to explain :
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 :

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.
(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)

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.

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 ?

Cheers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20150910/7ad6fd43/attachment.html>


More information about the Pd-dev mailing list