]>
Commit | Line | Data |
---|---|---|
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 | // | |
7adcbafe | 4 | // Copyright (C) 2002-2022 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 | |
748086b7 | 9 | // Free Software Foundation; either version 3, or (at your option) |
ddd69607 LR |
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 | |
748086b7 JJ |
18 | // with this library; see the file COPYING3. If not see |
19 | // <http://www.gnu.org/licenses/>. | |
ddd69607 | 20 | |
d1236680 RO |
21 | // { dg-do run } |
22 | // { dg-options "-pthread" } | |
23 | // { dg-require-effective-target pthread } | |
ddd69607 LR |
24 | |
25 | #include <string> | |
26 | #include <map> | |
27 | #include <vector> | |
1769232d | 28 | #include <pthread.h> |
ddd69607 | 29 | |
ddd69607 LR |
30 | const int max_thread_count = 8; |
31 | const int loops = 100000; | |
32 | ||
33 | const char* my_default = "Hallo Welt!"; | |
34 | ||
11f10e6b BK |
35 | const std::size_t upper_limit = 2500; |
36 | const std::size_t lower_limit = 1000; | |
ddd69607 LR |
37 | |
38 | typedef char charT; | |
39 | ||
40 | typedef std::string String; | |
41 | ||
42 | typedef String MyType; | |
43 | ||
44 | void* | |
45 | thread_main (void*) | |
46 | { | |
47 | typedef std::map<unsigned int,MyType> Map; | |
48 | typedef Map::value_type Value_Pair; | |
49 | Map myMap; | |
50 | ||
51 | for (int loop = 0; loop < loops; loop++) | |
52 | { | |
53 | String& str = myMap[loop]; | |
54 | str.append (my_default); | |
55 | myMap.insert (Value_Pair (loop, str)); | |
56 | ||
57 | if (myMap.size () > upper_limit) | |
58 | { | |
59 | while (myMap.size () > lower_limit) | |
60 | { | |
61 | Map::iterator it = myMap.begin (); | |
62 | myMap.erase (it); | |
63 | } | |
64 | } | |
65 | } | |
66 | ||
67 | return 0; | |
68 | } | |
69 | ||
70 | int | |
71 | main (void) | |
72 | { | |
73 | pthread_t tid[max_thread_count]; | |
74 | ||
87bd0274 | 75 | #if defined(__sun) && defined(__svr4__) && _XOPEN_VERSION >= 500 |
ddd69607 LR |
76 | pthread_setconcurrency (max_thread_count); |
77 | #endif | |
78 | ||
79 | for (int i = 0; i < max_thread_count; i++) | |
445877a9 | 80 | pthread_create (&tid[i], 0, thread_main, 0); |
ddd69607 LR |
81 | |
82 | for (int i = 0; i < max_thread_count; i++) | |
445877a9 | 83 | pthread_join (tid[i], 0); |
ddd69607 LR |
84 | |
85 | return 0; | |
86 | } |