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

123456789101112131415
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <stdint.h>
  3. volatile uint64_t x;
  4. int main(int argc, char *argv[])
  5. {
  6. uint64_t old, new = argc;
  7. (void)argv;
  8. do {
  9. old = __sync_val_compare_and_swap(&x, 0, 0);
  10. } while (!__sync_bool_compare_and_swap(&x, old, new));
  11. return old == new;
  12. }