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