On 03/02/13 02:10, Jeffrey Walton wrote:
Thanks Andrew.
So, it looks like I don't understand sequence points. Please forgive
my ignorance.
What does C/C++ and GCC offer to ensure writes are complete before
reads are performed on a value in a multi-threaded program?
Jeff
You are probably looking for a "memory barrier", rather than a "sequence
point". But even that will not be enough if you have an SMP system -
though it might let you get better results from your Googling. If
possible, your best bet is probably to use facilities provided by your
OS - but that is very much outside the scope of this mailing list.
Anyway, the simplest memory barrier in gcc is :
asm volatile("" ::: "memory");
This tells gcc that memory may be used in unexpected ways at this point
in the code - so any outstanding writes are handled before this point,
and no reads are started until after it. But that only applies at the
assembly code level - the compiler does not control things like caches,
write buffers, read-ahead buffers, etc.
mvh.,
David
On Sat, Feb 2, 2013 at 8:07 PM, Andrew Pinski <pins...@gmail.com> wrote:
On Sat, Feb 2, 2013 at 4:59 PM, Jeffrey Walton <noloa...@gmail.com> wrote:
Hi All,
How do I add a sequence point in my C/C++ code?
A semi-colon (end of the statement), a comma (but not as an argument
separator though) are both sequence points.
Thanks,
Andrew Pinski
Googling brings up a lot of 'volatile' hits, but I believe that's an
abuse of GCC's interpretation of volatile since I'm not working with
memory mapped hardware or registers.