atomic_cas.c (351B)
1 /* Atomic compare-exchange on a global: the ldaxr/stlxr CAS loop plus the 2 * branch on success. Exit: g becomes 42. */ 3 _Atomic int g = 40; 4 int test_main(void) { 5 int expected = 40; 6 __atomic_compare_exchange_n(&g, &expected, 42, 0, __ATOMIC_SEQ_CST, 7 __ATOMIC_SEQ_CST); 8 return __atomic_load_n(&g, __ATOMIC_SEQ_CST); 9 }