[ntp:hackers] [Gpsd-dev] GPSD shared-memory export is working

Dave Hart davehart at gmail.com
Sat Mar 26 16:48:59 UTC 2011

On Sat, Mar 26, 2011 at 2:57 PM, tz <thomas at mich.com> wrote:
> do {
>  u32 l1 = l-2;
>  u8 *d1 = d+1; * c1 = c, a, b;
>  a = *c1++;
>  read_barrier()
>  while( l1-- ) *d1++ = *c1++;
>  read_barrier()
>  b = *c1;
> } while( a != b );

I feel like a broken record, but byte-wide access is not atomic on all
architectures.  Use the native word size for things that need to be
atomic, namely the fetches into a and b, and use volatile liberally
(because the guarantee against compiler reordering applies only when
both accesses are volatile).

Dave Hart

More information about the hackers mailing list