A simple atomic operation sample :

a.c:

#include <stdio.h>

void main() {
    unsigned value = 0;

    unsigned ret = __atomic_fetch_add(&value, 1, 5);
    printf("Test: ret=%u, value=%u → %s\n",
          ret, value,
          (ret == 0 && value == 1) ? "Pass" : "Fail");
}

compile with TCC under arm linux.

If just compile without `libatomic.a`,

tcc a.c -o a

It will finish with `Pass`:
$ ./a
Test: ret=0, value=1 → Pass


If compile with `libatomic.a`, 

tcc a.c -o a "/usr/lib/gcc/aarch64-linux-gnu/9/libatomic.a"

It will finish with `Fail`:
$ ./a
Test: ret=4262792, value=0 → Fail




kbkp...@sina.com

_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to