Debian Codegraph @

gcc/testsuite/g++.dg/simulate-thread/atomics-2.C

raw
1 /* { dg-do link { target c++11 } } */
2 /* { dg-final { simulate-thread } } */
3 /* { dg-require-effective-target sync_int_long } */
4
5 using namespace std;
6
7 #include <atomic>
8 #include <limits.h>
9 #include <stdio.h>
10 #include "simulate-thread.h"
11
12 atomic_int atomi;
13
14 /* Non-atomic. Use a type wide enough to possibly coerce GCC into
15 moving things around. */
16 long double j;
17
18
19 /* Test that an atomic store synchronizes with an atomic load.
20
21 In this case, test that the store to <j> happens-before the atomic
22 store to <atomi>. Make sure the compiler does not reorder the
23 stores. */
24 __attribute__((noinline))
25 void simulate_thread_main()
26 {
27 j = 13.0;
28 atomi.store(1);
29 }
30
31 int main ()
32 {
33 simulate_thread_main();
34 simulate_thread_done();
35 return 0;
36 }
37
38 void simulate_thread_other_threads()
39 {
40 }
41
42 /* Verify that side-effects before an atomic store are correctly
43 synchronized with the an atomic load to the same location. */
44 int simulate_thread_step_verify()
45 {
46 if (atomi.load() == 1 && j != 13.0)
47 {
48 printf ("FAIL: invalid synchronization for atomic load/store.\n");
49 return 1;
50 }
51 return 0;
52 }
53
54
55 int simulate_thread_final_verify()
56 {
57 return simulate_thread_step_verify();
58 }