1 /* { dg-do run } */
2 /* { dg-options "-pthread" } */
3 /* { dg-require-effective-target pthread } */
4 
5 #include <pthread.h>
6 #include <stdlib.h>
7 
8 static _Atomic int sem1;
9 
f(void * va)10 static void *f(void *va)
11 {
12   void **p = va;
13   while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE));
14   exit(!*p);
15 }
16 
main(int argc)17 int main(int argc)
18 {
19   void *p = 0;
20   pthread_t thr;
21   if (pthread_create(&thr, 0, f, &p))
22     return 2;
23   // GCC used to RTL-DSE this store
24   p = &p;
25   __atomic_store_n(&sem1, 1, __ATOMIC_RELEASE);
26   int r = -1;
27   while (r < 0) asm("":"+r"(r));
28   return r;
29 }
30