test-sync-compare-and-swap.c 251 B

1234567891011121314
  1. #include <stdint.h>
  2. volatile uint64_t x;
  3. int main(int argc, char *argv[])
  4. {
  5. uint64_t old, new = argc;
  6. argv = argv;
  7. do {
  8. old = __sync_val_compare_and_swap(&x, 0, 0);
  9. } while (!__sync_bool_compare_and_swap(&x, old, new));
  10. return old == new;
  11. }