2011-11-08 12:13:41 +01:00
|
|
|
/* { dg-do run } */
|
2011-11-10 18:15:33 +01:00
|
|
|
/* { dg-options "-pthread" } */
|
2012-01-17 16:42:47 +01:00
|
|
|
/* { dg-skip-if "PR libitm/51822" { *-*-* } } */
|
2011-11-08 12:13:41 +01:00
|
|
|
/* Tests static constructors inside of transactional code. */
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
int f(int x) __attribute__((noinline,transaction_safe));
|
|
|
|
int f(int x)
|
|
|
|
{
|
|
|
|
static int y = x;
|
|
|
|
return y*x;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *thread (void *)
|
|
|
|
{
|
|
|
|
int bar;
|
|
|
|
__transaction_atomic { bar = f(10); }
|
|
|
|
if (bar != 100)
|
|
|
|
abort();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int bar;
|
|
|
|
|
|
|
|
// First, initialize y in another thread.
|
|
|
|
pthread_t pt;
|
|
|
|
pthread_create(&pt, NULL, thread, NULL);
|
|
|
|
pthread_join(pt, NULL);
|
|
|
|
|
|
|
|
// Now y should already be initialized.
|
|
|
|
__transaction_atomic { bar = f(20); }
|
|
|
|
if (bar != 200)
|
|
|
|
abort();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|