<div dir="ltr"><div style="font-size:12.8px">Hi Miller,<br></div><div style="font-size:12.8px"><div>You're right, for these objects the method will fail. One solution would be to offer another clock_new function with t_pdinstance as third argument but perhaps the solution goes too far and there are certainly others devs that create clocks on the fly.</div><div><br></div><div>Another (stupid?) proposition :</div><div>Perhaps it would be possible to extend the size of the objects in the pd_new function , for example :</div><div><i><font size="1">x = (t_pd *)t_getbytes(c->c_size + sizeof(t_pdinstance *);</font></i></div><div>to save the instance in the structure of the object :</div><div><i><font size="1">t_pdinstance *pt = (t_pdinstance *)((char *)x)+c->c_size;</font></i></div><div><i><font size="1">pt = pd_this;</font></i></div><div>and then we will be able to safely use some methods by retrieving this pd_instance on the fly.</div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I know this is not really a solution, but a start for thinking about a thread safe version of Pure Data. If it is one of your concern, I'll be pleased to discuss about it. Anyway my plugin works very well so I'm certainly going too far... but it must be my geek side.<br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Cheers</div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-09-10 17:54 GMT+02:00 Miller Puckette <span dir="ltr"><<a href="mailto:msp@ucsd.edu" target="_blank">msp@ucsd.edu</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">HI Pierre -<br>
<br>
Maybe I'm missing something but I don't think this would work.  Objects like<br>
pipe and makenote call clock_new on teh fly (and I can't see how to get pd_this<br>
to them safely).<br>
<br>
cheers<br>
<span class="HOEnZb"><font color="#888888">Miller<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Thu, Sep 10, 2015 at 11:22:47AM +0200, Pierre Guillot wrote:<br>
> Since few weeks, I work on a plugin that dynamically loads Pure Data<br>
> patches, creates a GUI depending on the graphical objects of the patch and<br>
> retrieves their parameters to link them with the automation system of the<br>
> host. Everything works fine, but I had some issues to manage several PD<br>
> instances with multiple threads (pdlib doesn't manage multiple instances).<br>
><br>
> I made my own implementation that solved the problem and I found 2 small<br>
> things that could really improve the development of applications with Pure<br>
> Data.<br>
><br>
> I try to explain :<br>
> The main problem isn't the loading of patches that can be managed using<br>
> locks but  running the pacthes in parallele. For what I've seen, attack<br>
> ships on fire off the shoulder of Orion... sorry I digress. For what I've<br>
> seen, there are only 2 things that cause problems : the dsp chains and the<br>
> clocks. Here my solutions :<br>
><br>
> 1 - "t_pdinstance*" in the prototypes of the functions "sched_tick()" and<br>
>  "dsp_tick()". This way, we don't need to call "pd_setinstance" at each dsp<br>
> tick so it is thread safe.<br>
> (we could have something like "pdinstance_sched_tick(t_pdinstance* x)" and<br>
> "pdinstance_dsp_tick(t_pdinstance* x)" to ensure the good working of<br>
> previous applications)<br>
><br>
> 2 -  "t_pdinstance*" in the structure of the clock. All the clock_new<br>
> functions seem to be called in the "creation" methods of the objects. If<br>
> when we load a patch and we create objects, "pd_this" is well defined, we<br>
> can initialize the reference "t_pdinstance*" of the clock with "pd_this"<br>
> and later when we'll call "clock_set" the clock will use its reference<br>
> instead of "pd_this". In this case, imagine that we send a  bang to a<br>
> [delay] in one instance during the loading of a pacth in another instance,<br>
> even if "pd_this" is not the good one, the clock will be added to the<br>
> clocks list of its instance.<br>
><br>
> For the moment, I don't use this updates (I manage everything with locks)<br>
> because I want to be compatible with future versions of Pure Data. But if<br>
> you think that can be a good thing, I can submit the code. Can I use GitHub<br>
> for this ?<br>
><br>
> Cheers<br>
<br>
</div></div><div class="HOEnZb"><div class="h5">> _______________________________________________<br>
> Pd-dev mailing list<br>
> <a href="mailto:Pd-dev@lists.iem.at">Pd-dev@lists.iem.at</a><br>
> <a href="http://lists.puredata.info/listinfo/pd-dev" rel="noreferrer" target="_blank">http://lists.puredata.info/listinfo/pd-dev</a><br>
<br>
</div></div></blockquote></div><br></div>