summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/tm/opt-1.c
blob: 87a8c72bd4337e8782431dd6aee537151219c604 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
}