#include <vector>
#include <list>
#include <string>
#if __GTHREADS
#ifdef _GLIBCXX_HAVE_UNISTD_H
#include <unistd.h> // To test for _POSIX_THREAD_PRIORITY_SCHEDULING
#endif
using namespace std;
#define NTHREADS 8
#define LOOPS 20
struct tt_t
{
char buf[100];
int i;
};
void*
thread_function (void* arg)
{
int myid __attribute__((unused)) = *(int*) arg;
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;
}
#if !__GXX_WEAK__ && _MT_ALLOCATOR_H
template class __gnu_cxx::__mt_alloc<tt_t>;
template class __gnu_cxx::__mt_alloc<std::_List_node<std::string*> >;
#endif
int
main ()
{
int worker;
pthread_t threads[NTHREADS];
int ids[NTHREADS];
void* status;
#if defined(__sun) && defined(__svr4__)
pthread_setconcurrency (NTHREADS);
#endif
pthread_attr_t tattr;
int ret = pthread_attr_init (&tattr);
#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
ret = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM);
#endif
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);
}
#else
int main (void) {}
#endif