[Ffmpeg-devel] alsa input / output

Rich Felker dalias
Sun Mar 25 04:46:05 CEST 2007


On Sat, Mar 24, 2007 at 09:11:34PM +0000, M?ns Rullg?rd wrote:
> Reimar D?ffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de> writes:
> 
> > Hello,
> > On Sat, Mar 24, 2007 at 02:17:58PM -0500, Rich Felker wrote:
> >> as long as it's the lock-free thing, this sounds good! but is there
> >> really such a thing as lock-free in this age where broken cpus like
> >> ppc allow memory writes to take place in any order unless you insert
> >> mem barriers? (and gcc is too broken to insert mem barriers itself
> >> when you use the volatile keyword...)
> 
> Careful, the volatile keyword does not necessarily guarantee SMP-safe
> code.

It would if volatile were implemented correctly, i.e. if it actually
forced the physical writes to be sequential and in one-to-one
correspondence with the logical writes. Sadly, defining volatile like
this is way outside the scope of the language standard (which only
defines an abstract language); afaik the only required function of the
volatile keyword in C is to make variables safe against longjmp.

> To be SMP-safe, you need both a compiler optimization barrier
> and a CPU memory barrier.  The former makes sure the compiler doesn't
> reorder instructions so a store happens later than you're expecting,
> and the latter forces the CPU to finish executing all I/O instructions
> and flush its write buffers.  The PPC has a very good instruction for
> this called eieio: enforce in-order execution of I/O.

And the compiler should generate this instruction whenever volatile
I/O occurs. Otherwise it's impossible to do in any sane way..

Rich




More information about the ffmpeg-devel mailing list