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