]> gcc.gnu.org Git - gcc.git/blame - libstdc++-v3/testsuite/thread/pthread5.cc
testsuite_hooks.h (func_callback): Declare copy constructor and assignment operator...
[gcc.git] / libstdc++-v3 / testsuite / thread / pthread5.cc
CommitLineData
ddd69607
LR
1// 2002-01-23 Loren J. Rittle <rittle@labs.mot.com> <ljrittle@acm.org>
2// Adpated from libstdc++/5464 submitted by jjessel@amadeus.net
3// Jean-Francois JESSEL (Amadeus SAS Development)
4//
f90e600a 5// Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
ddd69607
LR
6//
7// This file is part of the GNU ISO C++ Library. This library is free
8// software; you can redistribute it and/or modify it under the
9// terms of the GNU General Public License as published by the
10// Free Software Foundation; either version 2, or (at your option)
11// any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License along
19// with this library; see the file COPYING. If not, write to the Free
20// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21// USA.
22
515aab7c
RO
23// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* } }
24// { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* } }
ddd69607
LR
25// { dg-options "-pthreads" { target *-*-solaris* } }
26
27#include <vector>
28#include <list>
29#include <string>
30
31// Do not include <pthread.h> explicitly; if threads are properly
32// configured for the port, then it is picked up free from STL headers.
33
34#if __GTHREADS
3d7c150e 35#ifdef _GLIBCXX_HAVE_UNISTD_H
17a7afe0
JT
36#include <unistd.h> // To test for _POSIX_THREAD_PRIORITY_SCHEDULING
37#endif
38
ddd69607
LR
39using namespace std;
40
41#define NTHREADS 8
42#define LOOPS 20
43
44struct tt_t
45{
46 char buf[100];
47 int i;
48};
49
50void*
51thread_function (void* arg)
52{
11f10e6b 53 int myid __attribute__((unused)) = *(int*) arg;
ddd69607
LR
54 for (int i = 0; i < LOOPS; i++)
55 {
56 vector<tt_t> myvect1;
57
58 for (int j = 0; j < 2000; j++)
59 {
60 vector<tt_t> myvect2;
61 tt_t v;
62 v.i = j;
63 myvect1.push_back (v);
64 myvect2.push_back (v);
65 list<std::string *> mylist;
66 std::string string_array[4];
67 string_array[0] = "toto";
68 string_array[1] = "titi";
69 string_array[2] = "tata";
70 string_array[3] = "tutu";
71 for (int k = 0; k < 4; k++)
72 {
73 if (mylist.size ())
74 {
75 list<std::string *>::iterator aIt;
76 for (aIt = mylist.begin (); aIt != mylist.end (); ++aIt)
77 {
78 if ((*aIt) == &(string_array[k]))
79 abort ();
80 }
81 }
82 mylist.push_back (&(string_array[k]));
83 }
84 }
85 }
86
87 return arg;
88}
89
f90e600a
BK
90#if !__GXX_WEAK__ && _MT_ALLOCATOR_H
91// Explicitly instantiate for systems with no COMDAT or weak support.
92template class __gnu_cxx::__mt_alloc<tt_t>;
93template class __gnu_cxx::__mt_alloc<std::_List_node<std::string*> >;
94#endif
95
ddd69607 96int
11f10e6b 97main ()
ddd69607
LR
98{
99 int worker;
100 pthread_t threads[NTHREADS];
101 int ids[NTHREADS];
102 void* status;
103
104#if defined(__sun) && defined(__svr4__)
105 pthread_setconcurrency (NTHREADS);
106#endif
107
108 pthread_attr_t tattr;
109 int ret = pthread_attr_init (&tattr);
17a7afe0 110#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
ddd69607 111 ret = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM);
17a7afe0 112#endif
ddd69607
LR
113
114 for (worker = 0; worker < NTHREADS; worker++)
115 {
116 ids[worker] = worker;
117 if (pthread_create(&threads[worker], &tattr,
118 thread_function, &ids[worker]))
119 abort ();
120 }
121
122 for (worker = 0; worker < NTHREADS; worker++)
123 {
124 if (pthread_join(threads[worker], static_cast<void **>(&status)))
125 abort ();
126
127 if (*((int *)status) != worker)
128 abort ();
129 }
130
131 return (0);
132}
133#else
134int main (void) {}
135#endif
This page took 0.245528 seconds and 5 git commands to generate.