| 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 |
|
| 10 |
static void *f(void *va) |
| 11 |
{ |
| 12 |
void **p = va; |
| 13 |
while (!__atomic_load_n(&sem1, __ATOMIC_ACQUIRE)) |
| 14 |
sched_yield (); |
| 15 |
exit(!*p); |
| 16 |
} |
| 17 |
|
| 18 |
int main(int argc) |
| 19 |
{ |
| 20 |
void *p = 0; |
| 21 |
pthread_t thr; |
| 22 |
if (pthread_create(&thr, 0, f, &p)) |
| 23 |
return 2; |
| 24 |
// GCC used to RTL-DSE this store |
| 25 |
p = &p; |
| 26 |
__atomic_store_n(&sem1, 1, __ATOMIC_RELEASE); |
| 27 |
int r = -1; |
| 28 |
while (r < 0) |
| 29 |
{ |
| 30 |
sched_yield (); |
| 31 |
asm("":"+r"(r)); |
| 32 |
} |
| 33 |
return r; |
| 34 |
} |