This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Information on atomics in the gnu extensions: is a dereference atomic?
- From: Leo Ferres <leoferres at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 29 Apr 2014 09:11:41 -0400
- Subject: Information on atomics in the gnu extensions: is a dereference atomic?
- Authentication-results: sourceware.org; auth=none
Hello,
Suppose the following C code.
int t = __sync_fetch_and_add(&s->r, 1);
s is a struct with member r, which is an volatile int.
Is this an atomic operation, even if you include the indirection? In
other words, can a thread come between the dereferencing operation and
the atomic increment of another thread? If so, is there a solution
besides whileing with a compare and swap?
What about stdatomic.h in C11, is there a way to do what I want there?
Pointers to documentation on stdatomic, or the gnu extensions are
greatly appreciated (I know about http://gcc.gnu.org/wiki/Atomic,
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1349.htm, and
http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html).
Thanks for your time.
Leo
--
Leo Ferres, Ph.D.
Assistant Professor
Department of Computer Science
University of ConcepciÃn, ConcepciÃn,
Chile