]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/locale/cons/12658_thread-1.cc
Simplify dg-options for tests using pthreads
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / locale / cons / 12658_thread-1.cc
1 // { dg-do run { target *-*-freebsd* *-*-dragonfly* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-rtems* *-*-darwin* } }
2 // { dg-options "-pthread" { target *-*-freebsd* *-*-dragonfly* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* } }
3 // { dg-require-namedlocale "en_US.ISO8859-1" }
4 // { dg-require-namedlocale "fr_FR.ISO8859-15" }
5
6 // Copyright (C) 2004-2016 Free Software Foundation, Inc.
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 3, 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 COPYING3. If not see
21 // <http://www.gnu.org/licenses/>.
22
23 // 22.1.1.2 locale constructors and destructors [lib.locale.cons]
24
25 #include <locale>
26 #include <pthread.h>
27 #include <testsuite_hooks.h>
28
29 const int max_thread_count = 20;
30 //const int max_loop_count = 1000000; // orig value
31 const int max_loop_count = 100000;
32 const int max_locales = 10;
33
34 void* thread_main(void*)
35 {
36 try
37 {
38 std::locale loc_c = std::locale::classic();
39 std::locale loc[max_locales];
40 for (int j = 0; j < max_locales; ++j)
41 loc[j] = std::locale(j % 2 ? ISO_8859(1,en_US) : ISO_8859(15,fr_FR));
42
43 for (int i = 0; i < max_loop_count; ++i)
44 {
45 int k = i % max_locales;
46 loc[k] = std::locale::global(loc[k]);
47
48 if (i % 37 == 0)
49 loc[k] = loc[k].combine<std::ctype<char> >(loc_c);
50 }
51 }
52 catch (...) { }
53 return 0;
54 }
55
56 int
57 main()
58 {
59 pthread_t tid[max_thread_count];
60
61 for (int i = 0; i < max_thread_count; i++)
62 pthread_create (&tid[i], 0, thread_main, 0);
63
64 for (int i = 0; i < max_thread_count; i++)
65 pthread_join (tid[i], 0);
66
67 return 0;
68 }