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:22:20 EEST

On 7/7/07, Lars Luthman <lars.luthman@email-addr-hidden> wrote:
> On Sat, 2007-07-07 at 12:03 +0200, Arnold Krille wrote:

> > And if you only sync two threads and each of them has its own flag (for
> > write), there shouldn't be any race-conditions and its easier to use a
> > bool-variable than semaphore->bla().
>
> I guess so. Can you always be sure that writing to word-sized variables
> is atomic on SMP systems?

Mostly yes, assuming the storage location is word-aligned which it
normally will be (due to the compiler).

I vaguely recall that some now old Sun SPARC and Motorola 68K machines
may have presented problems in that area. But, as a practical constraint
it should work OK (AFAIK). It is generally necessary for an SMP implementation
to guarantee coherency on a cache line granularity. Since a word-aligned
word will generally not cross cache lines, you can assume that hardware
will ensure you at least always get either the old or the new value
when looking
at it.

> Although if you only check for 0 or not 0 I guess it doesn't matter.

The problem with a largish struct is that hardware often does not ensure
that another thread sees only the old or new value. It could see the new value
of the flag but the old value of some of the other fields. If so, you need a
memory fence instruction of some sort.

-- 
 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:04 EEST