Debian Codegraph @

libitm/testsuite/libitm.c++/static_ctor.C

raw
1 /* { dg-do run } */
2 /* { dg-options "-pthread" } */
3 /* { dg-skip-if "PR libitm/51822" { *-*-* } } */
4 /* Tests static constructors inside of transactional code. */
5
6 #include <pthread.h>
7 #include <stdlib.h>
8
9 int f(int x) __attribute__((noinline,transaction_safe));
10 int f(int x)
11 {
12 static int y = x;
13 return y*x;
14 }
15
16 static void *thread (void *)
17 {
18 int bar;
19 __transaction_atomic { bar = f(10); }
20 if (bar != 100)
21 abort();
22 return 0;
23 }
24
25 int main()
26 {
27 int bar;
28
29 // First, initialize y in another thread.
30 pthread_t pt;
31 pthread_create(&pt, NULL, thread, NULL);
32 pthread_join(pt, NULL);
33
34 // Now y should already be initialized.
35 __transaction_atomic { bar = f(20); }
36 if (bar != 200)
37 abort();
38
39 return 0;
40 }