Added Compiler Support for _Cilk_spawn and _Cilk_sync for C++.
[official-gcc.git] / gcc / testsuite / g++.dg / cilk-plus / CK / catch_exc.cc
blob0633d19030ce2ae48db56acb7ca4eec6090f4ed1
1 /* { dg-options "-fcilkplus" } */
2 /* { dg-do run { target i?86-*-* x86_64-*-* arm*-*-* } } */
3 /* { dg-options "-fcilkplus -lcilkrts" { target { i?86-*-* x86_64-*-* arm*-*-* } } } */
5 #include <assert.h>
6 #include <unistd.h>
7 #if HAVE_IO
8 #include <cstdio>
9 #include <cilk/cilk_api.h>
10 #endif
11 #include <cstdlib>
14 void func(int volatile* steal_me)
16 while (! (*steal_me))
18 usleep(2000);
20 #if HAVE_IO
21 printf("Foo executing on %d\n", __cilkrts_get_worker_number());
22 #endif
23 throw 5;
26 void my_test()
28 volatile int steal_me = 0;
30 try
32 _Cilk_spawn func(&steal_me);
33 #if HAVE_IO
34 printf("Continuation executing on %d\n",
35 __cilkrts_get_worker_number());
36 #endif
37 steal_me = 1;
38 _Cilk_sync;
39 goto bad;
42 catch (int x)
44 #if HAVE_IO
45 printf("We caught x = %d\n", x);
46 #endif
47 assert(x == 5);
49 if (0)
51 bad:
52 #if HAVE_IO
53 printf("We should not be here!\n");
54 #endif
55 __builtin_abort ();
60 int main()
62 my_test();
63 #if HAVE_IO
64 printf("PASSED\n");
65 #endif
66 return 0;