aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/cilk-plus/CK/catch_exc.cc
blob: 0633d19030ce2ae48db56acb7ca4eec6090f4ed1 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* { dg-options "-fcilkplus" } */
/* { dg-do run { target i?86-*-* x86_64-*-* arm*-*-* } } */
/* { dg-options "-fcilkplus -lcilkrts" { target { i?86-*-* x86_64-*-* arm*-*-* } } } */

#include <assert.h>
#include <unistd.h>
#if HAVE_IO
#include <cstdio>
#include <cilk/cilk_api.h>
#endif
#include <cstdlib>


void func(int volatile* steal_me) 
{
  while (! (*steal_me)) 
    {
      usleep(2000);
    }
#if HAVE_IO
  printf("Foo executing on %d\n", __cilkrts_get_worker_number());
#endif
  throw 5;
}

void my_test() 
{
  volatile int steal_me = 0;

  try 
    {
      _Cilk_spawn func(&steal_me);
#if HAVE_IO
      printf("Continuation executing on %d\n",
	     __cilkrts_get_worker_number());
#endif
      steal_me = 1;
      _Cilk_sync;
      goto bad;
    }

  catch (int x) 
    {
#if HAVE_IO
      printf("We caught x = %d\n", x);
#endif
      assert(x == 5);
    }
  if (0) 
    {
    bad:
#if HAVE_IO
      printf("We should not be here!\n");
#endif
      __builtin_abort ();
    }
}


int main() 
{
  my_test();
#if HAVE_IO
  printf("PASSED\n");
#endif
  return 0;
}