<div dir="ltr">So, for a complete guaranteed situation a [readsf~]-like mechanics is a good solution?<div>"Generate Pd messages from outside the main thread" means to generate something in Pd, i.e. with a multithreaded externals, but from a child thread?</div><div><br></div><div>Best,</div><div><br></div><div>Marco</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-08-23 18: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">Well, Pd itself only calls that lock from its main thread - so theoretically<br>
that call won't ever block.  But it's provided in case someone wants to<br>
generate Pd messages from outside the main thread.  If you do that, Pd's<br>
call to the lock can block - whether the time it's blocked can be bounded<br>
depends on the behavior of  the other thread and the OS's ability to give<br>
control quickly to a blocked thread when another thread releases the lock.<br>
It's probably very hard to guarantee but probably works 99% of the time in<br>
reasonable situations.<br>
<br>
cheers<br>
<span class="HOEnZb"><font color="#888888">Miller<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Tue, Aug 23, 2016 at 06:26:16PM +0200, Marco Matteo Markidis wrote:<br>
> Thank you Miller for your answer.<br>
><br>
> This afternoon I just took a look of s_audio_paring.c/h.<br>
> Do you think the lock in the scheduler can be a problem? It's meaningful a<br>
> lock free queue between audio and worker thread?<br>
><br>
> Best,<br>
> Marco<br>
><br>
> 2016-08-23 18:13 GMT+02:00 Miller Puckette <<a href="mailto:msp@ucsd.edu">msp@ucsd.edu</a>>:<br>
><br>
> > There's a good, byte-stream lock-free fifo in pd/src/s_audio_paring.c .<br>
> > (It's borrowed from portaudio).  The difficulty there would be the<br>
> > necessity<br>
> > of encoding everything into byte streams.  Perhaps just sprintf/sscanf will<br>
> > do it for you.<br>
> ><br>
> > cheers<br>
> > Miller<br>
> ><br>
> > On Tue, Aug 23, 2016 at 03:49:20PM +0200, Marco Matteo Markidis wrote:<br>
> > > Dear all,<br>
> > ><br>
> > > I'm developing an external that has two threads, one audio thread and one<br>
> > > worker thread. The audio thread contains all usual stuff; while the<br>
> > worker<br>
> > > thread computes calculations (I need knn searches and so on for my<br>
> > > resynthesis) and put them in a data structure. At the end of<br>
> > calculations,<br>
> > > the worker thread atomically CAS the data structure.<br>
> > > Actually, I'm using a [readsf~]-like mechanics with pthread signal to<br>
> > > communicate between threads.<br>
> > ><br>
> > > I would like to remove lock and use a lock free system. I don't know if<br>
> > it<br>
> > > feasible. Moreover I don't know if it has some sense, because Pd locks a<br>
> > > mutex in scheduler and I don't know if a lock free implementation could<br>
> > be<br>
> > > a right solution.<br>
> > ><br>
> > > In the case it could be a solution, I will start with a SPSC circular<br>
> > queue<br>
> > > and I will use atomic CAS to swap the data structure.<br>
> > ><br>
> > > Best regards,<br>
> > ><br>
> > > Marco<br>
> ><br>
> > > ______________________________<wbr>_________________<br>
> > > <a href="mailto:Pd-list@lists.iem.at">Pd-list@lists.iem.at</a> mailing list<br>
> > > UNSUBSCRIBE and account-management -> <a href="https://lists.puredata.info/" rel="noreferrer" target="_blank">https://lists.puredata.info/</a><br>
> > listinfo/pd-list<br>
> ><br>
> ><br>
<br>
> ______________________________<wbr>_________________<br>
> <a href="mailto:Pd-list@lists.iem.at">Pd-list@lists.iem.at</a> mailing list<br>
> UNSUBSCRIBE and account-management -> <a href="https://lists.puredata.info/listinfo/pd-list" rel="noreferrer" target="_blank">https://lists.puredata.info/<wbr>listinfo/pd-list</a><br>
<br>
</div></div></blockquote></div><br></div>