1 #include <pthread.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <stdio.h> 5 #include <unistd.h> 6 7 void *volatile mem; 8 volatile int len; 9 10 void *Thread(void *p) { 11 while ((p = __atomic_load_n(&mem, __ATOMIC_ACQUIRE)) == 0) 12 usleep(100); 13 memset(p, 0, len); 14 return 0; 15 } 16 17 extern "C" void libfunc() { 18 pthread_t t; 19 pthread_create(&t, 0, Thread, 0); 20 len = 10; 21 __atomic_store_n(&mem, malloc(len), __ATOMIC_RELEASE); 22 pthread_join(t, 0); 23 free(mem); 24 fprintf(stderr, "OK\n"); 25 } 26