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