OSDN Git Service

* config/i386/winnt.c (i386_pe_asm_output_aligned_decl_common): Revert
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 30_threads / thread / this_thread / 3.cc
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 "" }
8
9 // Copyright (C) 2008 Free Software Foundation, Inc.
10 //
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.
16
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.
21
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.
26
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.
35
36 #include <chrono>
37 #include <thread>
38 #include <system_error>
39 #include <testsuite_hooks.h>
40
41 namespace chr = std::chrono;
42
43 void foo()
44 {
45   bool test __attribute__((unused)) = true;
46
47   chr::system_clock::time_point begin = chr::system_clock::now();
48   chr::microseconds ms(500);
49
50   std::this_thread::sleep_for(ms);
51   
52   VERIFY( (chr::system_clock::now() - begin) >= ms );
53 }
54
55 int main()
56 {
57   bool test __attribute__((unused)) = true;
58
59   try 
60     {
61       std::thread t(foo);
62       t.join();
63     }
64   catch (const std::system_error&)
65     {
66       VERIFY( false );
67     }
68   catch (...)
69     {
70       VERIFY( false );
71     }
72
73   return 0;
74 }