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