2002-01-24 08:35:11 +01:00
|
|
|
// 2002-01-23 Loren J. Rittle <rittle@labs.mot.com> <ljrittle@acm.org>
|
|
|
|
// Adpated from libstdc++/5464 submitted by jjessel@amadeus.net
|
|
|
|
// Jean-Francois JESSEL (Amadeus SAS Development)
|
|
|
|
//
|
2007-03-02 17:21:30 +01:00
|
|
|
// Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
|
|
|
|
// Free Software Foundation, Inc.
|
2002-01-24 08:35:11 +01:00
|
|
|
//
|
|
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
|
|
// software; you can redistribute it and/or modify it under the
|
|
|
|
// terms of the GNU General Public License as published by the
|
|
|
|
// Free Software Foundation; either version 2, or (at your option)
|
|
|
|
// any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this library; see the file COPYING. If not, write to the Free
|
2005-08-17 04:28:44 +02:00
|
|
|
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
2002-01-24 08:35:11 +01:00
|
|
|
// USA.
|
|
|
|
|
2007-07-16 19:21:10 +02:00
|
|
|
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
|
|
|
|
// { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
|
2002-01-24 08:35:11 +01:00
|
|
|
// { dg-options "-pthreads" { target *-*-solaris* } }
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <list>
|
|
|
|
#include <string>
|
2007-03-02 19:11:15 +01:00
|
|
|
#include <cstdlib>
|
2007-03-02 17:21:30 +01:00
|
|
|
#include <pthread.h>
|
2002-01-24 08:35:11 +01:00
|
|
|
|
2003-07-05 06:05:45 +02:00
|
|
|
#ifdef _GLIBCXX_HAVE_UNISTD_H
|
2002-10-29 02:10:52 +01:00
|
|
|
#include <unistd.h> // To test for _POSIX_THREAD_PRIORITY_SCHEDULING
|
|
|
|
#endif
|
|
|
|
|
2002-01-24 08:35:11 +01:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#define NTHREADS 8
|
|
|
|
#define LOOPS 20
|
|
|
|
|
|
|
|
struct tt_t
|
|
|
|
{
|
|
|
|
char buf[100];
|
|
|
|
int i;
|
|
|
|
};
|
|
|
|
|
|
|
|
void*
|
|
|
|
thread_function (void* arg)
|
|
|
|
{
|
2003-09-23 22:03:30 +02:00
|
|
|
int myid __attribute__((unused)) = *(int*) arg;
|
2002-01-24 08:35:11 +01:00
|
|
|
for (int i = 0; i < LOOPS; i++)
|
|
|
|
{
|
|
|
|
vector<tt_t> myvect1;
|
|
|
|
|
|
|
|
for (int j = 0; j < 2000; j++)
|
|
|
|
{
|
|
|
|
vector<tt_t> myvect2;
|
|
|
|
tt_t v;
|
|
|
|
v.i = j;
|
|
|
|
myvect1.push_back (v);
|
|
|
|
myvect2.push_back (v);
|
|
|
|
list<std::string *> mylist;
|
|
|
|
std::string string_array[4];
|
|
|
|
string_array[0] = "toto";
|
|
|
|
string_array[1] = "titi";
|
|
|
|
string_array[2] = "tata";
|
|
|
|
string_array[3] = "tutu";
|
|
|
|
for (int k = 0; k < 4; k++)
|
|
|
|
{
|
|
|
|
if (mylist.size ())
|
|
|
|
{
|
|
|
|
list<std::string *>::iterator aIt;
|
|
|
|
for (aIt = mylist.begin (); aIt != mylist.end (); ++aIt)
|
|
|
|
{
|
|
|
|
if ((*aIt) == &(string_array[k]))
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mylist.push_back (&(string_array[k]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-09-23 22:03:30 +02:00
|
|
|
main ()
|
2002-01-24 08:35:11 +01:00
|
|
|
{
|
|
|
|
int worker;
|
|
|
|
pthread_t threads[NTHREADS];
|
|
|
|
int ids[NTHREADS];
|
|
|
|
void* status;
|
|
|
|
|
2005-02-18 12:53:18 +01:00
|
|
|
#if defined(__sun) && defined(__svr4__) && _XOPEN_VERSION >= 500
|
2002-01-24 08:35:11 +01:00
|
|
|
pthread_setconcurrency (NTHREADS);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
pthread_attr_t tattr;
|
|
|
|
int ret = pthread_attr_init (&tattr);
|
2002-10-29 02:10:52 +01:00
|
|
|
#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
|
2002-01-24 08:35:11 +01:00
|
|
|
ret = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM);
|
2002-10-29 02:10:52 +01:00
|
|
|
#endif
|
2002-01-24 08:35:11 +01:00
|
|
|
|
|
|
|
for (worker = 0; worker < NTHREADS; worker++)
|
|
|
|
{
|
|
|
|
ids[worker] = worker;
|
|
|
|
if (pthread_create(&threads[worker], &tattr,
|
|
|
|
thread_function, &ids[worker]))
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (worker = 0; worker < NTHREADS; worker++)
|
|
|
|
{
|
|
|
|
if (pthread_join(threads[worker], static_cast<void **>(&status)))
|
|
|
|
abort ();
|
|
|
|
|
|
|
|
if (*((int *)status) != worker)
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|