OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [thread/] [pthread6.cc] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 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
//
4
// Copyright (C) 2002, 2003, 2005 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20
// USA.
21
 
22
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* } }
23
// { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* } }
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
const int max_thread_count = 8;
34
const int loops = 100000;
35
 
36
const char* my_default = "Hallo Welt!";
37
 
38
const std::size_t upper_limit = 2500;
39
const std::size_t lower_limit = 1000;
40
 
41
typedef char charT;
42
 
43
typedef std::string String;
44
 
45
typedef String MyType;
46
 
47
void*
48
thread_main (void*)
49
{
50
  typedef std::map<unsigned int,MyType> Map;
51
  typedef Map::value_type Value_Pair;
52
  Map myMap;
53
 
54
  for (int loop = 0; loop < loops; loop++)
55
    {
56
      String& str = myMap[loop];
57
      str.append (my_default);
58
      myMap.insert (Value_Pair (loop, str));
59
 
60
      if (myMap.size () > upper_limit)
61
        {
62
          while (myMap.size () > lower_limit)
63
            {
64
              Map::iterator it = myMap.begin ();
65
              myMap.erase (it);
66
            }
67
        }
68
    }
69
 
70
  return 0;
71
}
72
 
73
int
74
main (void)
75
{
76
  pthread_t tid[max_thread_count];
77
 
78
#if defined(__sun) && defined(__svr4__) && _XOPEN_VERSION >= 500
79
  pthread_setconcurrency (max_thread_count);
80
#endif
81
 
82
  for (int i = 0; i < max_thread_count; i++)
83
    pthread_create (&tid[i], NULL, thread_main, 0);
84
 
85
  for (int i = 0; i < max_thread_count; i++)
86
    pthread_join (tid[i], NULL);
87
 
88
  return 0;
89
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.