Debian Codegraph @

gcc/testsuite/gcc.target/loongarch/pr107713-1.c

raw
1 /* { dg-do run } */
2 /* { dg-require-effective-target pthread } */
3 /* { dg-options "-pthread" } */
4
5 #include <pthread.h>
6
7 char x, x1, x2;
8
9 void *
10 work1 (void *)
11 {
12 for (int i = 0; i < 100; i++)
13 x1 = __atomic_exchange_n (&x, x1, __ATOMIC_SEQ_CST);
14 return NULL;
15 }
16
17 void *
18 work2 (void *)
19 {
20 for (int i = 0; i < 100; i++)
21 x2 = __atomic_exchange_n (&x, x2, __ATOMIC_SEQ_CST);
22 return NULL;
23 }
24
25 void
26 test (void)
27 {
28 x = 0;
29 x1 = 1;
30 x2 = 2;
31 pthread_t w1, w2;
32 if (pthread_create (&w1, NULL, work1, NULL) != 0)
33 __builtin_abort ();
34 if (pthread_create (&w2, NULL, work2, NULL) != 0)
35 __builtin_abort ();
36 if (pthread_join (w1, NULL) != 0)
37 __builtin_abort ();
38 if (pthread_join (w2, NULL) != 0)
39 __builtin_abort ();
40 if ((x ^ x1 ^ x2) != 3)
41 __builtin_abort ();
42 }
43
44 int
45 main ()
46 {
47 int i;
48 for (i = 0; i < 10000; i++)
49 test ();
50 }