| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-fgnu-tm -O" } */ |
| 3 |
|
| 4 |
extern void usleep (int) __attribute__((transaction_pure)); |
| 5 |
extern int rand(void) __attribute__((pure, transaction_pure)); |
| 6 |
extern int printf (const char *, ...); |
| 7 |
extern void *malloc (__SIZE_TYPE__) __attribute__((malloc)); |
| 8 |
extern void xyzzy (void * (*)(void *)); |
| 9 |
|
| 10 |
typedef struct |
| 11 |
{ |
| 12 |
int id; |
| 13 |
} parm; |
| 14 |
|
| 15 |
int gvar; |
| 16 |
|
| 17 |
void *hello(void *arg) |
| 18 |
{ |
| 19 |
parm *p=(parm *)arg; |
| 20 |
int tmp = p->id; |
| 21 |
int tmp3; |
| 22 |
printf ("Thread reads %d.\n", tmp); |
| 23 |
__transaction_atomic |
| 24 |
{ |
| 25 |
int tmp2 = gvar; |
| 26 |
usleep ((int) (10.0*rand()/(10+1.0))/100); |
| 27 |
gvar = tmp + tmp2; |
| 28 |
tmp3 = gvar; |
| 29 |
} |
| 30 |
printf("tmp3 = %d\n", tmp3); |
| 31 |
return 0; |
| 32 |
} |
| 33 |
|
| 34 |
int |
| 35 |
main() |
| 36 |
{ |
| 37 |
int i, n = rand(); |
| 38 |
|
| 39 |
for (i=0; i<n; i++) |
| 40 |
xyzzy (hello); |
| 41 |
|
| 42 |
return 0; |
| 43 |
} |