<div dir="ltr">Sorry for the delay.<br>#1 I agree. Seems like a workaround. Ultimately it should be clear in the source code when a static is meant to be shared across threads or not.<br>     Seems like something that could be properly implemented in the future?<br>
<br>#2  Sounds good, but Im not familiar with which variables are symbol table related, DSP chain related, etc.<br>      Im of the mind, Id just like to put them *all* into one structure, to get a stable release, and then individual variables can be pulled back out in future as the need arises.<br>
     Id be inclined to throw everything into one structure, and name things according to which file they originated in:<br><br>example,  firstnet in d_fftroutine.c would live as an entry<br><br>struct PDinstance {<br>    ...<br>
    FFT_NET *d_fftroutine_firstnet;<br>    ...<br>} <br><br>This would allow one to at least see where the variable is used.<br><br> #3  Peter mentions that in order to support legacy code, all API calls would need to be mirrored, with and without the pd-instance variable.<br>
I don&#39;t think C allows for overloading, so would this require a separate name for all the functions?<br>Would supporting two parallel APIs be wanted though, or just lead to confusion?<br>Is this in order to support previously compiled objects (Dlls)?<br>
<br>-Rob<br><br><br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Dec 9, 2013 at 5:30 AM, Kjetil Matheussen <span dir="ltr">&lt;<a href="mailto:k.s.matheussen@gmail.com" target="_blank">k.s.matheussen@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Miller,<br>
<br>
Idea #1 sounds quite good, except that it sounds hacky<br>
and that performance might go down notifiable because<br>
of thread switching. The extra amount of code necessary<br>
to switch threads doesn&#39;t sound like too much work.<br>
<br>
So I like idea #2 much better. The limitation of only one<br>
DSP chain was the only good reason for implementing<br>
multiple pd instances for Radium. If you implement #2,<br>
that&#39;s probably good enough for Radium, and most likely<br>
good enough for most others too. At least, it&#39;s a very<br>
good start.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Sun, Dec 8, 2013 at 6:53 PM, Miller Puckette &lt;<a href="mailto:msp@ucsd.edu">msp@ucsd.edu</a>&gt; wrote:<br>
&gt; Hi all -<br>
&gt;<br>
&gt; two idea, neither of them as general but perhaps much easier to pull off:<br>
&gt;<br>
&gt; 1.  make macros like:<br>
&gt; #define STATIC static __thread<br>
&gt;<br>
&gt; and rely on gcc&#39;s per-thread static storage mechanism.  This would involve<br>
&gt; some global search-and-replace action but wouldn&#39;t clutter the code too badly.<br>
&gt; The downside is it would require that each instance of libpd would have to<br>
&gt; run in its own thread - As Peter pointed out to me, in many situations the<br>
&gt; programmer can&#39;t even determine at compile time whether this would be true<br>
&gt; or not.<br>
&gt;<br>
&gt; I&#39;m not sure but I think other C compilers besides gcc might support __thread<br>
&gt; these days.<br>
&gt;<br>
&gt; 2.  Just make the symbol table and DSP chain per-instance,  and leave the rest<br>
&gt; alone.  This only solves a subset of the problem (things like the search path<br>
&gt; would remain global) but my intuition has it that fixing these two would be<br>
&gt; enough so that people could practically make patches that don&#39;t interfere<br>
&gt; with each other.  (Making the symbol table per-instance would keep things<br>
&gt; like arrays, send/receives, etc., from cross-talking.)<br>
&gt;<br>
&gt; The result wouldn&#39;t be thread-safe; however, combining this with the<br>
&gt; __thread idea from above would probably work, and then you&#39;d have something<br>
&gt; that would at least work (although perhaps slightly differently) in<br>
&gt; same-thread and multi-thread contexts.<br>
&gt;<br>
&gt; These are just ideas - if there&#39;s enough interest I can pull (2) off quite<br>
&gt; easily; (1) would be a global search-and-replace mess that would likely<br>
&gt; conflict with every source-code patch out there (e.g., all the patches that<br>
&gt; are applied for Pd extended) so I&#39;d need a real good reason to inflict that<br>
&gt; one on the world.<br>
&gt;<br>
&gt; cheers<br>
&gt; Miller<br>
&gt;<br>
&gt; On Sun, Dec 08, 2013 at 10:12:03AM +0100, Kjetil Matheussen wrote:<br>
&gt;&gt; Excellent plan.<br>
&gt;&gt;<br>
&gt;&gt; In my branch of libpd on Github, I&#39;ve solved the Pd multiple<br>
&gt;&gt; instances problem by letting the linker take care of separating<br>
&gt;&gt; the global variables. However, using the linker causing various<br>
&gt;&gt; problems, such as making it very difficult to load externals,<br>
&gt;&gt; and it should probably also be considered a hack.<br>
&gt;&gt; Your plan (the plan I didn&#39;t bother doing in my branch) is quite<br>
&gt;&gt; undoubtedly the proper way to do it, and hopefully I would have time to<br>
&gt;&gt; help. At least I would be helping to debug it afterwards,<br>
&gt;&gt; because I would start using this system (in the Radium music editor),<br>
&gt;&gt; instead of my own, to embed Pd instances.<br>
&gt;&gt;<br>
&gt;&gt; And an advantage to Pd itself might be that the source could be clearer when<br>
&gt;&gt; variables that belongs to the instance, actually are denoted as such<br>
&gt;&gt; in the text.<br>
&gt;&gt;<br>
&gt;&gt; There is also quite microscopic concern, which is that the added<br>
&gt;&gt; amount of text could make the source more difficult to read,<br>
&gt;&gt; here and there. Maybe a very short variable name for the pd instance,<br>
&gt;&gt; such as &quot;p&quot;, &quot;pi&#39;, would be a good idea. (i.e. not &quot;pure_data_instance&quot;).<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Sat, Dec 7, 2013 at 10:20 PM, Rob Bairos &lt;<a href="mailto:rob@derivative.ca">rob@derivative.ca</a>&gt; wrote:<br>
&gt;&gt; &gt; Sorry, most of my original post got cut off.<br>
&gt;&gt; &gt; Here&#39;s the rest (minus the list of symbols) in case its causing a problem:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; From my understanding, the current proposed solution is to take all statics<br>
&gt;&gt; &gt; and globals,<br>
&gt;&gt; &gt; encapsulate them in one object, and pass that object to all api calls.<br>
&gt;&gt; &gt; Peter further suggested legacy api is maintained by having them call the new<br>
&gt;&gt; &gt; api with a default instance object.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I did a little bit of hunting, using objdump on the current dll, to get a<br>
&gt;&gt; &gt; rough list of all the globals and statics currently involved.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Im thinking the *_class and *_sym static pointers are in fact constant, and<br>
&gt;&gt; &gt; need only one shared instance.  That would leave about 320 variables<br>
&gt;&gt; &gt; remaining.<br>
&gt;&gt; &gt; Many of these variables are constant arrays, strings, etc.<br>
&gt;&gt; &gt; And many seem to be used only as a shortcut for passing data between two<br>
&gt;&gt; &gt; functions, possibly bringing down the number further.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Im toying with the idea of taking on this task if anyone&#39;s interested.<br>
&gt;&gt; &gt; I may require some tips and help from the forum, in terms of creating a<br>
&gt;&gt; &gt; branch, explanation of some statics etc.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; So how feasible is this? Am I on the right track?<br>
&gt;&gt; &gt; Thanks very much,<br>
&gt;&gt; &gt; Rob Bairos.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; Pd-dev mailing list<br>
&gt;&gt; &gt; <a href="mailto:Pd-dev@iem.at">Pd-dev@iem.at</a><br>
&gt;&gt; &gt; <a href="http://lists.puredata.info/listinfo/pd-dev" target="_blank">http://lists.puredata.info/listinfo/pd-dev</a><br>
&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Pd-dev mailing list<br>
&gt;&gt; <a href="mailto:Pd-dev@iem.at">Pd-dev@iem.at</a><br>
&gt;&gt; <a href="http://lists.puredata.info/listinfo/pd-dev" target="_blank">http://lists.puredata.info/listinfo/pd-dev</a><br>
</div></div></blockquote></div><br></div>