2014-02-05 Balaji V. Iyer <balaji.v.iyer@intel.com>
[official-gcc.git] / gcc / testsuite / g++.dg / cilk-plus / CK / catch_exc.cc
blobff5ccbf5d249b071b47f834dcf70349f1e9f7f61
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*-*-* } } } */
4 /* { dg-skip-if "" { *-*-* } { "-O1" } { "" } } */
6 #include <assert.h>
7 #include <unistd.h>
8 #if HAVE_IO
9 #include <cstdio>
10 #include <cilk/cilk_api.h>
11 #endif
12 #include <cstdlib>
15 void func(int volatile* steal_me)
17 while (! (*steal_me))
19 usleep(2000);
21 #if HAVE_IO
22 printf("Foo executing on %d\n", __cilkrts_get_worker_number());
23 #endif
24 throw 5;
27 void my_test()
29 volatile int steal_me = 0;
31 try
33 _Cilk_spawn func(&steal_me);
34 #if HAVE_IO
35 printf("Continuation executing on %d\n",
36 __cilkrts_get_worker_number());
37 #endif
38 steal_me = 1;
39 _Cilk_sync;
40 goto bad;
43 catch (int x)
45 #if HAVE_IO
46 printf("We caught x = %d\n", x);
47 #endif
48 assert(x == 5);
50 if (0)
52 bad:
53 #if HAVE_IO
54 printf("We should not be here!\n");
55 #endif
56 __builtin_abort ();
61 int main()
63 my_test();
64 #if HAVE_IO
65 printf("PASSED\n");
66 #endif
67 return 0;