summaryrefslogtreecommitdiffstats
path: root/libitm/testsuite/libitm.c/simple-2.c
blob: c77d75dcf5160fc7964b8759bfe0060437c77f03 (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
/* Simplest test involving real threads.  Verify we get the correct answer.  */

/* { dg-options "-pthread" } */

#include <stdlib.h>
#include <pthread.h>

static int x;

static void *start (void *dummy __attribute__((unused)))
{
  __transaction_atomic { x++; }
  return NULL;
}

int main()
{
  pthread_t p[10];
  int i;

  for (i = 0; i < 10; ++i)
    pthread_create (p+i, NULL, start, NULL);

  for (i = 0; i < 10; ++i)
    pthread_join  (p[i], NULL);

  if (x != 10)
    abort ();

  return 0;
}
OpenPOWER on IntegriCloud