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)
5 // Copyright (C) 2002, 2003 Free Software Foundation, Inc.
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)
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.
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,
23 // { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* } }
24 // { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* } }
25 // { dg-options "-pthreads" { target *-*-solaris* } }
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.
35 #ifdef _GLIBCXX_HAVE_UNISTD_H
36 #include <unistd.h> // To test for _POSIX_THREAD_PRIORITY_SCHEDULING
51 thread_function (void* arg
)
53 int myid
= *(int*) arg
;
54 for (int i
= 0; i
< LOOPS
; i
++)
58 for (int j
= 0; j
< 2000; 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
++)
75 list
<std::string
*>::iterator aIt
;
76 for (aIt
= mylist
.begin (); aIt
!= mylist
.end (); ++aIt
)
78 if ((*aIt
) == &(string_array
[k
]))
82 mylist
.push_back (&(string_array
[k
]));
91 main (int argc
, char *argv
[])
94 pthread_t threads
[NTHREADS
];
98 #if defined(__sun) && defined(__svr4__)
99 pthread_setconcurrency (NTHREADS
);
102 pthread_attr_t tattr
;
103 int ret
= pthread_attr_init (&tattr
);
104 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
105 ret
= pthread_attr_setscope(&tattr
, PTHREAD_SCOPE_SYSTEM
);
108 for (worker
= 0; worker
< NTHREADS
; worker
++)
110 ids
[worker
] = worker
;
111 if (pthread_create(&threads
[worker
], &tattr
,
112 thread_function
, &ids
[worker
]))
116 for (worker
= 0; worker
< NTHREADS
; worker
++)
118 if (pthread_join(threads
[worker
], static_cast<void **>(&status
)))
121 if (*((int *)status
) != worker
)