Re: [LAD] Best practice for sharing complex data structures with a jack callback function

From: Jack O'Quin <jack.oquin@email-addr-hidden>
Date: Sat Jul 07 2007 - 13:12:52 EEST

On 7/7/07, Fons Adriaensen <fons@email-addr-hidden> wrote:
> On Fri, Jul 06, 2007 at 10:13:36PM -0500, Jack O'Quin wrote:
>
> > Beware! Flags are not enough to guarantee that you get
> > a coherent copy of the structure. The safest technique is
> > using "guard" words at the start and end of the structure.
> > ...
>
> Depends on how they are used.

And on what platform. Beware of SMP hardware with non-
coherent caches. In general, it is not portable to assume that
stores done by one thread are seen in the same order in
another thread. On most PC-class Intel or AMD systems
that does work. That is called "strong storage ordering".
PowerPC, however, only guarantees "weak storage ordering".
Some NUMA machines my not guarantee any at all. This is
a tradeoff between hardware performance and programming
convenience. Some system designs opt for the former.

> If the callback unconditionally updates the data each
> time it runs then you are right.
>
> If the system is that ownership of the struct is trans-
> ferred between the two parties and only the owner ever
> writes, then a simple flag will do.

The OP specified that "only the jack callback writes to the
structures". My suggestion would not work in the general
case of multiple update threads. For that, you need
some kind of atomic compare-and-swap or increment
operation or a very high resolution timer.

-- 
 joq
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/mailman/listinfo.cgi/linux-audio-dev
Received on Sat Jul 7 16:15:03 2007

This archive was generated by hypermail 2.1.8 : Sat Jul 07 2007 - 16:15:03 EEST