This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: __sync_fetch
- From: Hei Chan <structurechart at yahoo dot com>
- To: Hei Chan <structurechart at yahoo dot com>, "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Sat, 17 Nov 2012 23:04:44 -0800 (PST)
- Subject: Re: __sync_fetch
- References: <1353134056.24702.YahooMailNeo@web165004.mail.bf1.yahoo.com>
- Reply-to: Hei Chan <structurechart at yahoo dot com>
Hi,
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_*()?
Thanks in advance.
Cheers,
Hei
________________________________
From: Hei Chan <structurechart@yahoo.com>
To: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Sent: Friday, November 16, 2012 10:34 PM
Subject: __sync_fetch
Hi,
I am using GCC 4.1.2, and so no __atomic*().
I am looking at http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Atomic-Builtins.html
I see __sync_fetch_and_*(), but I don't see __sync_fetch().? Is it because the built-in routines support integral scalar or pointer type that is up to 8 bytes in length, and so the read is automatically atomic anyway?
Thanks in advance.
Cheers,
Hei