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