diff options
Diffstat (limited to 'gcc/testsuite/gcc.dg/tm/opt-1.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/tm/opt-1.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/tm/opt-1.c b/gcc/testsuite/gcc.dg/tm/opt-1.c new file mode 100644 index 00000000000..87a8c72bd43 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tm/opt-1.c @@ -0,0 +1,43 @@ +/* { dg-do compile } */ +/* { dg-options "-fgnu-tm -O" } */ + +extern void usleep (int) __attribute__((transaction_pure)); +extern int rand(void) __attribute__((pure, transaction_pure)); +extern int printf (const char *, ...); +extern void *malloc (__SIZE_TYPE__) __attribute__((malloc)); +extern void xyzzy (void * (*)(void *)); + +typedef struct +{ + int id; +} parm; + +int gvar; + +void *hello(void *arg) +{ + parm *p=(parm *)arg; + int tmp = p->id; + int tmp3; + printf ("Thread reads %d.\n", tmp); + __transaction_atomic + { + int tmp2 = gvar; + usleep ((int) (10.0*rand()/(10+1.0))/100); + gvar = tmp + tmp2; + tmp3 = gvar; + } + printf("tmp3 = %d\n", tmp3); + return 0; +} + +int +main() +{ + int i, n = rand(); + + for (i=0; i<n; i++) + xyzzy (hello); + + return 0; +} |