]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/locale/cons/12658_thread-2.cc
testsuite_hooks.cc: Remove try_named_locale.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / locale / cons / 12658_thread-2.cc
CommitLineData
5a66cfb2
PR
1// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* } }
2// { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* } }
3// { dg-options "-pthreads" { target *-*-solaris* } }
f63a8495 4// { dg-require-namedlocale "" }
5a66cfb2 5
f63a8495 6// Copyright (C) 2004, 2005 Free Software Foundation
5a66cfb2
PR
7//
8// This file is part of the GNU ISO C++ Library. This library is free
9// software; you can redistribute it and/or modify it under the
10// terms of the GNU General Public License as published by the
11// Free Software Foundation; either version 2, or (at your option)
12// any later version.
13
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18
19// You should have received a copy of the GNU General Public License along
20// with this library; see the file COPYING. If not, write to the Free
21// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22// USA.
23
24// 22.1.1.2 locale constructors and destructors [lib.locale.cons]
25
26#include <locale>
27#include <pthread.h>
8063a355
PC
28#include <testsuite_hooks.h>
29
5a66cfb2
PR
30const int max_thread_count = 20;
31//const int max_loop_count = 1000000; // orig value
32const int max_loop_count = 100000;
33const int max_locales = 10;
9a2ba7af
PC
34std::locale loc[max_locales];
35
5a66cfb2
PR
36void* thread_main(void*)
37{
6dde938c 38 try
5a66cfb2 39 {
6dde938c
BK
40 for (int i = 0; i < max_loop_count; ++i)
41 {
42 int k = i % max_locales;
9a2ba7af 43 std::locale::global(loc[k]);
6dde938c 44 }
5a66cfb2 45 }
6dde938c 46 catch (...) { }
5a66cfb2
PR
47 return 0;
48}
49
50int
51main()
52{
53 pthread_t tid[max_thread_count];
6dde938c 54
9a2ba7af 55 for (int j = 0; j < max_locales; ++j)
f63a8495 56 loc[j] = std::locale(j % 2 ? "en_US" : "fr_FR");
9a2ba7af 57
5a66cfb2 58 for (int i = 0; i < max_thread_count; i++)
9a2ba7af 59 pthread_create(&tid[i], NULL, thread_main, 0);
5a66cfb2
PR
60
61 for (int i = 0; i < max_thread_count; i++)
9a2ba7af 62 pthread_join(tid[i], NULL);
5a66cfb2
PR
63
64 return 0;
65}