This commit was manufactured by cvs2svn to create branch
[official-gcc.git] / libstdc++-v3 / testsuite / 22_locale / locale / cons / 12658_thread.cc
blob3a89d371f62b97befbdfb58e08fd1ad44b5e6cd2
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* } }
5 // Copyright (C) 2004 Free Software Foundation
6 //
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)
11 // any later version.
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,
21 // USA.
23 // 22.1.1.2 locale constructors and destructors [lib.locale.cons]
25 #include <locale>
26 #include <pthread.h>
28 const int max_thread_count = 20;
29 //const int max_loop_count = 1000000; // orig value
30 const int max_loop_count = 100000;
31 const int max_locales = 10;
33 void* thread_main(void*)
35 try
37 std::locale loc_c = std::locale::classic();
38 std::locale loc[max_locales];
39 for (int j = 0; j < max_locales; ++j)
40 loc[j] = std::locale(j % 2 ? "en_US" : "fr_FR");
42 for (int i = 0; i < max_loop_count; ++i)
44 int k = i % max_locales;
45 loc[k] = std::locale::global(loc[k]);
47 if (i % 37 == 0)
48 loc[k] = loc[k].combine<std::ctype<char> >(loc_c);
51 catch (...) { }
52 return 0;
55 int
56 main()
58 pthread_t tid[max_thread_count];
60 for (int i = 0; i < max_thread_count; i++)
61 pthread_create (&tid[i], NULL, thread_main, 0);
63 for (int i = 0; i < max_thread_count; i++)
64 pthread_join (tid[i], NULL);
66 return 0;