libstdc++: Run tests on RTEMS
[official-gcc.git] / libstdc++-v3 / testsuite / 30_threads / packaged_task / members / at_thread_exit.cc
blob564bc9d417bc855693ff70282de4a9b4581cdba6
1 // { dg-do run { target *-*-freebsd* *-*-dragonfly* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-rtems* *-*-darwin* powerpc-ibm-aix* } }
2 // { dg-options " -std=gnu++11 -pthread" { target *-*-freebsd* *-*-dragonfly* *-*-netbsd* *-*-linux* *-*-gnu* powerpc-ibm-aix* } }
3 // { dg-options " -std=gnu++11 -pthreads" { target *-*-solaris* } }
4 // { dg-options " -std=gnu++11 " { target *-*-cygwin *-*-rtems* *-*-darwin* } }
5 // { dg-require-cstdint "" }
6 // { dg-require-gthreads "" }
7 // { dg-require-atomic-builtins "" }
9 // Copyright (C) 2014-2015 Free Software Foundation, Inc.
11 // This file is part of the GNU ISO C++ Library. This library is free
12 // software; you can redistribute it and/or modify it under the
13 // terms of the GNU General Public License as published by the
14 // Free Software Foundation; either version 3, or (at your option)
15 // any later version.
17 // This library is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
22 // You should have received a copy of the GNU General Public License along
23 // with this library; see the file COPYING3. If not see
24 // <http://www.gnu.org/licenses/>.
27 #include <future>
28 #include <testsuite_hooks.h>
30 bool executed = false;
32 int execute(int i) { executed = true; return i + 1; }
34 std::future<int> f1;
36 bool ready(std::future<int>& f)
38 return f.wait_for(std::chrono::milliseconds(1)) == std::future_status::ready;
41 void test01()
43 bool test __attribute__((unused)) = true;
45 std::packaged_task<int(int)> p1(execute);
46 f1 = p1.get_future();
48 p1.make_ready_at_thread_exit(1);
50 VERIFY( executed );
51 VERIFY( p1.valid() );
52 VERIFY( !ready(f1) );
55 int main()
57 std::thread t{test01};
58 t.join();
59 VERIFY( ready(f1) );
60 VERIFY( f1.get() == 2 );