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

From: Lars Luthman <lars.luthman@email-addr-hidden>
Date: Sat Jul 07 2007 - 13:08:07 EEST

On Sat, 2007-07-07 at 12:03 +0200, Arnold Krille wrote:
> Am Samstag, 7. Juli 2007 schrieb Lars Luthman:
> > On Sat, 2007-07-07 at 02:34 +0200, Fons Adriaensen wrote:
> > > * The callback has to know when it can (re)write the object.
> > > Clearly it should never wait on a sema, and it is already
> > > periodic, so here you can use a flag in the object.
> > Is there any advantage in using a simple flag instead of a semaphore and
> > sem_trywait()?
>
> A semaphore might mislead you to use wait()/lock() in the wrong thread...

Seriously now, I'm not _that_ stupid. =)

> 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?

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

--ll

_______________________________________________
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