aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cilk-plus/CK/catch_exc.cc
blob: 09ddf8b28e3242410ba642ff1031065563023549 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* { 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>

#ifdef __cplusplus
extern "C" {
#endif

extern int __cilkrts_set_param (const char *, const char *);

#ifdef __cplusplus
}
#endif


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() 
{
  /* Ensure more than one worker.  */
  if (__cilkrts_set_param("nworkers", "2") != 0)
    __builtin_abort();

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