------- Comment #18 from tim at klingt dot org 2008-05-05 09:09 ------- hm, if that code is broken, what about the following one on x86_64 (__sync_bool_compare_and_swap_16 requires an alignment of 16 byte)?
struct __attribute__((aligned(16))) foo_t { foo_t(int a = 0, int b = 0): a_(a), b_(b) {} void CAS (foo_t const & rhs) { typedef int TItype __attribute__ ((mode (TI))); union cu { long c[2]; TItype l; }; cu old; old.c[0] = (long)a_; old.c[1] = (long)b_; cu nw; nw.c[0] = (long)rhs.a_; nw.c[1] = (long)rhs.b_; __sync_bool_compare_and_swap_16(reinterpret_cast<volatile foo_t*>(this), old.l, nw.l); } int a_, b_; }; int main() { foo_t * f = new foo_t(); f->CAS(foo_t(1,2)); } thanks, tim -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36054