]> gcc.gnu.org Git - gcc.git/blame - libstdc++-v3/testsuite/23_containers/list/pthread5.cc
Update copyright years.
[gcc.git] / libstdc++-v3 / testsuite / 23_containers / list / 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//
5624e564 5// Copyright (C) 2002-2015 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
748086b7 10// Free Software Foundation; either version 3, or (at your option)
ddd69607
LR
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
748086b7
JJ
19// with this library; see the file COPYING3. If not see
20// <http://www.gnu.org/licenses/>.
ddd69607 21
75a8a745
JW
22// { dg-do run { target *-*-freebsd* *-*-dragonfly* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-darwin* } }
23// { dg-options "-pthread" { target *-*-freebsd* *-*-dragonfly* *-*-netbsd* *-*-linux* *-*-gnu* } }
ddd69607
LR
24// { dg-options "-pthreads" { target *-*-solaris* } }
25
26#include <vector>
27#include <list>
28#include <string>
debac9f4 29#include <cstdlib>
1769232d 30#include <pthread.h>
ddd69607 31
3d7c150e 32#ifdef _GLIBCXX_HAVE_UNISTD_H
17a7afe0
JT
33#include <unistd.h> // To test for _POSIX_THREAD_PRIORITY_SCHEDULING
34#endif
35
ddd69607
LR
36#define NTHREADS 8
37#define LOOPS 20
38
39struct tt_t
40{
41 char buf[100];
42 int i;
43};
44
45void*
46thread_function (void* arg)
47{
875d0f10
BK
48 typedef std::vector<tt_t> vector_type;
49 typedef std::list<std::string*> list_type;
50
11f10e6b 51 int myid __attribute__((unused)) = *(int*) arg;
ddd69607
LR
52 for (int i = 0; i < LOOPS; i++)
53 {
875d0f10 54 vector_type myvect1;
ddd69607
LR
55
56 for (int j = 0; j < 2000; j++)
57 {
875d0f10 58 vector_type myvect2;
ddd69607
LR
59 tt_t v;
60 v.i = j;
61 myvect1.push_back (v);
62 myvect2.push_back (v);
875d0f10 63 list_type mylist;
ddd69607
LR
64 std::string string_array[4];
65 string_array[0] = "toto";
66 string_array[1] = "titi";
67 string_array[2] = "tata";
68 string_array[3] = "tutu";
69 for (int k = 0; k < 4; k++)
70 {
71 if (mylist.size ())
72 {
875d0f10 73 list_type::iterator aIt;
ddd69607
LR
74 for (aIt = mylist.begin (); aIt != mylist.end (); ++aIt)
75 {
76 if ((*aIt) == &(string_array[k]))
77 abort ();
78 }
79 }
80 mylist.push_back (&(string_array[k]));
81 }
82 }
83 }
84
85 return arg;
86}
87
88int
11f10e6b 89main ()
ddd69607
LR
90{
91 int worker;
92 pthread_t threads[NTHREADS];
93 int ids[NTHREADS];
94 void* status;
95
87bd0274 96#if defined(__sun) && defined(__svr4__) && _XOPEN_VERSION >= 500
ddd69607
LR
97 pthread_setconcurrency (NTHREADS);
98#endif
99
100 pthread_attr_t tattr;
567d4027 101 int ret __attribute__((unused)) = pthread_attr_init (&tattr);
17a7afe0 102#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
ddd69607 103 ret = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM);
17a7afe0 104#endif
ddd69607
LR
105
106 for (worker = 0; worker < NTHREADS; worker++)
107 {
108 ids[worker] = worker;
109 if (pthread_create(&threads[worker], &tattr,
110 thread_function, &ids[worker]))
111 abort ();
112 }
113
114 for (worker = 0; worker < NTHREADS; worker++)
115 {
116 if (pthread_join(threads[worker], static_cast<void **>(&status)))
117 abort ();
118
119 if (*((int *)status) != worker)
120 abort ();
121 }
122
123 return (0);
124}
This page took 1.19175 seconds and 5 git commands to generate.