]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/30_threads/thread/cons/terminate.cc
Remove dg-require-cstdint directive from tests
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 30_threads / thread / cons / terminate.cc
1 // Copyright (C) 2017-2018 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-options "-pthread" }
20 // { dg-require-effective-target c++11 }
21 // { dg-require-effective-target pthread }
22 // { dg-require-gthreads "" }
23
24 #include <thread>
25 #include <exception>
26 #include <cstdlib>
27 #if !_GLIBCXX_USE_C99_STDLIB && defined _GLIBCXX_HAVE_UNISTD_H
28 # include <unistd.h>
29 #endif
30
31 void handle_terminate()
32 {
33 #if _GLIBCXX_USE_C99_STDLIB
34 std::_Exit(0);
35 #elif defined _GLIBCXX_HAVE_UNISTD_H
36 _exit(0);
37 #else
38 std::exit(0);
39 #endif
40 }
41
42 void f() { throw 1; }
43
44 void
45 test01()
46 {
47 std::set_terminate(handle_terminate);
48 std::thread t(f);
49 // This should call the terminate handler and exit with zero status:
50 t.join();
51 // Should not reach here:
52 std::abort();
53 }
54
55 int
56 main()
57 {
58 test01();
59 }