OSDN Git Service

70fd9ead58a8c89fb06ebdc14398d00e4e3ff8a3
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / thread / pthread3.cc
1 // 2002-01-23  Loren J. Rittle <rittle@labs.mot.com> <ljrittle@acm.org>
2 // Adpated from libstdc++/5347 submitted by markus.breuer@materna.de
3 //
4 // Copyright (C) 2002, 2003 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library.  This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING.  If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 // USA.
21
22 // { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* } }
23 // { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* } }
24 // { dg-options "-pthreads" { target *-*-solaris* } }
25
26 #include <sstream>
27
28 // Do not include <pthread.h> explicitly; if threads are properly
29 // configured for the port, then it is picked up free from STL headers.
30
31 #if __GTHREADS
32
33 const int max_thread_count = 2;
34 const int max_loop_count = 1000000;
35
36 void*
37 thread_main (void *)
38 {
39    for (int i = 0; i < max_loop_count; i++)
40      std::ostringstream oss;
41
42    return 0;
43 }
44
45 int
46 main()
47 {
48   pthread_t tid[max_thread_count];
49
50 #if defined(__sun) && defined(__svr4__)
51   pthread_setconcurrency (max_thread_count);
52 #endif
53
54   for (int i = 0; i < max_thread_count; i++)
55     pthread_create (&tid[i], NULL, thread_main, 0);
56
57   for (int i = 0; i < max_thread_count; i++)
58     pthread_join (tid[i], NULL);
59
60   return 0;
61 }
62 #else
63 int main (void) {}
64 #endif