Merged revisions 143552,143554,143557,143560,143562,143564-143567,143570-143573,14357...
[official-gcc.git] / libstdc++-v3 / testsuite / 30_threads / this_thread / 3.cc
blob564bd1f704e6ffcb4b159b6e87bea784fc6bca51
1 // { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
2 // { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
3 // { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
4 // { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
5 // { dg-require-cstdint "" }
6 // { dg-require-gthreads "" }
7 // { dg-require-nanosleep "" }
9 // Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
24 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 // USA.
27 // As a special exception, you may use this file as part of a free software
28 // library without restriction. Specifically, if other files instantiate
29 // templates or use macros or inline functions from this file, or you compile
30 // this file and link it with other files to produce an executable, this
31 // file does not by itself cause the resulting executable to be covered by
32 // the GNU General Public License. This exception does not however
33 // invalidate any other reasons why the executable file might be covered by
34 // the GNU General Public License.
36 #include <chrono>
37 #include <thread>
38 #include <system_error>
39 #include <testsuite_hooks.h>
41 namespace chr = std::chrono;
43 void foo()
45 bool test __attribute__((unused)) = true;
47 chr::system_clock::time_point begin = chr::system_clock::now();
48 chr::microseconds ms(500);
50 std::this_thread::sleep_for(ms);
52 VERIFY( (chr::system_clock::now() - begin) >= ms );
55 int main()
57 bool test __attribute__((unused)) = true;
59 try
61 std::thread t(foo);
62 t.join();
64 catch (const std::system_error&)
66 VERIFY( false );
68 catch (...)
70 VERIFY( false );
73 return 0;