This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Information on atomics in the gnu extensions: is a dereference atomic?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]