]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/30_threads/thread/cons/terminate.cc
Fix libstdc++ testsuite to handle VxWorks gthreads implementation
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 30_threads / thread / cons / terminate.cc
1 // Copyright (C) 2017-2020 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-do run }
19 // { dg-additional-options "-pthread" { target pthread } }
20 // { dg-require-effective-target c++11 }
21 // { dg-require-gthreads "" }
22
23 #include <thread>
24 #include <exception>
25 #include <cstdlib>
26 #if !_GLIBCXX_USE_C99_STDLIB && defined _GLIBCXX_HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
29
30 void handle_terminate()
31 {
32 #if _GLIBCXX_USE_C99_STDLIB
33 std::_Exit(0);
34 #elif defined _GLIBCXX_HAVE_UNISTD_H
35 _exit(0);
36 #else
37 std::exit(0);
38 #endif
39 }
40
41 void f() { throw 1; }
42
43 void
44 test01()
45 {
46 std::set_terminate(handle_terminate);
47 std::thread t(f);
48 // This should call the terminate handler and exit with zero status:
49 t.join();
50 // Should not reach here:
51 std::abort();
52 }
53
54 int
55 main()
56 {
57 test01();
58 }