"memory" clobber in synchronization primitives

Roland McGrath roland@frob.com
Mon Aug 31 22:03:00 GMT 1998


> On ppc, arguably no such clobber is required, because anyone who
> expects memory ordering between threads has to use a 'sync'
> instruction anyway.  The actual compare_and_swap procedure has two
> 'sync' instructions surrounding the main code, which are 'asm
> volatile' and therefore memory barriers.

I take this as agreement that memory barriers are appropriate, which was my
quesiton.

> Note that on ppc, 'volatile' is not at present sufficient for
> multiprocessor synchronization.  Arguably, this should be fixed in
> egcs---certainly it would make the embedded people happy.

Please clarify.  `volatile' is not sufficient on the x86 either to
guarantee coherent values when one processor writes while another reads.  I
do not think it needs to be or should be--that's what the explicit
synchronization primitives are for.  The purpose of `volatile' is to ensure
that reads and writes cannot be optimized out, for things like mapped
device registers, and interrupt handlers changing memory values.  I do not
think that `volatile' should be made to, or be expected to, do MP
synchronization.  Programmers can use the synchronization facilities.



More information about the Libc-hacker mailing list