]> 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
fbd26352 1// Copyright (C) 2017-2019 Free Software Foundation, Inc.
cd1abcb6 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
a8815ed2 18// { dg-do run }
19// { dg-options "-pthread" }
cd1abcb6 20// { dg-require-effective-target c++11 }
a8815ed2 21// { dg-require-effective-target pthread }
cd1abcb6 22// { dg-require-gthreads "" }
23
24#include <thread>
25#include <exception>
26#include <cstdlib>
929ac4c6 27#if !_GLIBCXX_USE_C99_STDLIB && defined _GLIBCXX_HAVE_UNISTD_H
28# include <unistd.h>
29#endif
cd1abcb6 30
31void handle_terminate()
32{
929ac4c6 33#if _GLIBCXX_USE_C99_STDLIB
cd1abcb6 34 std::_Exit(0);
929ac4c6 35#elif defined _GLIBCXX_HAVE_UNISTD_H
36 _exit(0);
37#else
38 std::exit(0);
39#endif
cd1abcb6 40}
41
42void f() { throw 1; }
43
44void
45test01()
46{
47 std::set_terminate(handle_terminate);
48 std::thread t(f);
929ac4c6 49 // This should call the terminate handler and exit with zero status:
cd1abcb6 50 t.join();
929ac4c6 51 // Should not reach here:
cd1abcb6 52 std::abort();
53}
54
55int
56main()
57{
58 test01();
59}