On Sat, Nov 17, 2012 at 11:04 PM, Hei Chan <structurechart@xxxxxxxxx> wrote: > > After searching more for info, it seems like even though on a > 64-bit machine, reading a long (i.e. 8 bytes) is one operation, it > might not give the "correct" value: > http://gcc.gnu.org/ml/gcc/2008-03/msg00201.html > > And so, we have to use __sync_fetch_and_add(&x, 0) to read? > > Could > someone elaborate a situation that reading a long variable won't get > the correct value given that all writes in the application use > __sync_fetch_*()? If you always use __sync_fetch_and_add(&x, 0) to read a value, and you always use __sync_fetch_and_add to write the value also with some appropriate detla, then all the accesses to that variable should be atomic with sequential consistency. That should be true on any processors that implements __sync_fetch_and_add in the appropriate size. Ian