#include <stdio.h>
#include <stdatomic.h>
#include "pthread.h"
int cc = 0;
int test=0;
void* task2(void *arg)
{
printf("s2");
while(1){
int expect = 0;
atomic_compare_exchange_weak_explicit (&cc, &expect, 1, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
printf("%d", test);
}
}
void main()
{
pthread_t t1;
pthread_create(&t1, NULL, task2, NULL);
printf("s1");
while(1){
int expect = 0;
atomic_compare_exchange_weak_explicit (&cc, &expect, 1, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
test = 0;
atomic_compare_exchange_strong(&cc, &expect, 1);
}
}
__sync_synchronize();
aarch64-linux-gnu-gcc main.c -g -lpthread -static
aarch64-linux-gnu-objdump -S -d a.out > a1.s