]> gcc.gnu.org Git - gcc.git/blame - libstdc++-v3/testsuite/thread/pthread6.cc
testsuite_hooks.h (func_callback): Declare copy constructor and assignment operator...
[gcc.git] / libstdc++-v3 / testsuite / thread / pthread6.cc
CommitLineData
ddd69607
LR
1// 2002-01-23 Loren J. Rittle <rittle@labs.mot.com> <ljrittle@acm.org>
2// Adpated from libstdc++/5444 submitted by markus.breuer@materna.de
3//
8a4680db 4// Copyright (C) 2002, 2003 Free Software Foundation, Inc.
ddd69607
LR
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
515aab7c
RO
22// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* } }
23// { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* } }
ddd69607
LR
24// { dg-options "-pthreads" { target *-*-solaris* } }
25
26#include <string>
27#include <map>
28#include <vector>
29
30// Do not include <pthread.h> explicitly; if threads are properly
31// configured for the port, then it is picked up free from STL headers.
32
33#if __GTHREADS
34
35const int max_thread_count = 8;
36const int loops = 100000;
37
38const char* my_default = "Hallo Welt!";
39
11f10e6b
BK
40const std::size_t upper_limit = 2500;
41const std::size_t lower_limit = 1000;
ddd69607
LR
42
43typedef char charT;
44
45typedef std::string String;
46
47typedef String MyType;
48
49void*
50thread_main (void*)
51{
52 typedef std::map<unsigned int,MyType> Map;
53 typedef Map::value_type Value_Pair;
54 Map myMap;
55
56 for (int loop = 0; loop < loops; loop++)
57 {
58 String& str = myMap[loop];
59 str.append (my_default);
60 myMap.insert (Value_Pair (loop, str));
61
62 if (myMap.size () > upper_limit)
63 {
64 while (myMap.size () > lower_limit)
65 {
66 Map::iterator it = myMap.begin ();
67 myMap.erase (it);
68 }
69 }
70 }
71
72 return 0;
73}
74
f90e600a
BK
75#if !__GXX_WEAK__ && _MT_ALLOCATOR_H
76// Explicitly instantiate for systems with no COMDAT or weak support.
77template class __gnu_cxx::__mt_alloc<std::_Rb_tree_node<std::pair<unsigned int const, std::string> > >;
78#endif
79
ddd69607
LR
80int
81main (void)
82{
83 pthread_t tid[max_thread_count];
84
85#if defined(__sun) && defined(__svr4__)
86 pthread_setconcurrency (max_thread_count);
87#endif
88
89 for (int i = 0; i < max_thread_count; i++)
90 pthread_create (&tid[i], NULL, thread_main, 0);
91
92 for (int i = 0; i < max_thread_count; i++)
93 pthread_join (tid[i], NULL);
94
95 return 0;
96}
97#else
98int main (void) {}
99#endif
This page took 0.228527 seconds and 5 git commands to generate.