]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/ext/rope/pthread7-rope.cc
Check MAX_FIXED_MODE_SIZE on bit-field in C++.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / ext / rope / pthread7-rope.cc
CommitLineData
1976f0d9
LR
1// 2003-05-03 Loren J. Rittle <rittle@labs.mot.com> <ljrittle@acm.org>
2//
748086b7
JJ
3// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009
4// Free Software Foundation, Inc.
1976f0d9
LR
5//
6// This file is part of the GNU ISO C++ Library. This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
748086b7 9// Free Software Foundation; either version 3, or (at your option)
1976f0d9
LR
10// any later version.
11//
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License along
748086b7
JJ
18// with this library; see the file COPYING3. If not see
19// <http://www.gnu.org/licenses/>.
1976f0d9 20
40f5cc95
RO
21// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
22// { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
2aa89cbb 23// { dg-options "-pthreads" { target *-*-solaris* } }
1976f0d9
LR
24
25#include <ext/rope>
26#include <cstring>
1769232d 27#include <pthread.h>
1976f0d9
LR
28#include <testsuite_hooks.h>
29
1976f0d9
LR
30const int max_thread_count = 4;
31const int max_loop_count = 10000;
32
e3f78d9b
BK
33typedef __gnu_cxx::rope<char, std::allocator<char> > rope_type;
34rope_type foo2;
35rope_type foo4;
1976f0d9 36
11f10e6b 37void* thread_main(void *)
1976f0d9
LR
38{
39 // To see a problem with gcc 3.3 and before, set a break point here.
40 // Single step through c_str implementation, call sched_yield after
41 // capture of NULL __old_c_string in any thread. Single step
42 // through another thread past that same point. Now, one thread
43 // will receive a bad pointer return. Adding dummy sched_yield
44 // should never change program semantics under POSIX threads.
45 const char* data4 = foo4.c_str();
46
47 // Please note that the memory leak in the rope implementation with
48 // this test case, existed before and after fixing this bug...
11f10e6b 49 bool test __attribute__((unused)) = true;
1976f0d9 50 VERIFY( !std::strcmp (data4, "barbazbonglehellohellohello") );
11f10e6b 51 return 0;
1976f0d9
LR
52}
53
54int
55main()
56{
11f10e6b
BK
57 bool test __attribute__((unused)) = true;
58
1976f0d9
LR
59 pthread_t tid[max_thread_count];
60
87bd0274 61#if defined(__sun) && defined(__svr4__) && _XOPEN_VERSION >= 500
1976f0d9
LR
62 pthread_setconcurrency (max_thread_count);
63#endif
64
e3f78d9b 65 rope_type foo;
1976f0d9
LR
66 foo += "bar";
67 foo += "baz";
68 foo += "bongle";
69 const char* data = foo.c_str();
70 VERIFY( !std::strcmp (data, "barbazbongle") );
71
72 const char* data2;
73 {
1976f0d9
LR
74 foo2 += "bar2";
75 foo2 += "baz2";
76 foo2 += "bongle2";
77 data2 = foo2.c_str();
78 VERIFY( !std::strcmp (data2, "bar2baz2bongle2") );
79 }
80
e3f78d9b 81 rope_type foo3 ("hello");
1976f0d9
LR
82 const char* data3 = foo3.c_str();
83 VERIFY( !std::strcmp (data3, "hello") );
84
85 for (int j = 0; j < max_loop_count; j++)
86 {
87 foo4 = foo;
88 foo4 += foo3;
89 foo4 += foo3;
90 foo4 += foo3;
91
92 for (int i = 0; i < max_thread_count; i++)
93 pthread_create (&tid[i], NULL, thread_main, 0);
94
95 for (int i = 0; i < max_thread_count; i++)
96 pthread_join (tid[i], NULL);
97 }
98
63041e68
PC
99 VERIFY( !std::strcmp (data, "barbazbongle") );
100 VERIFY( !std::strcmp (data2, "bar2baz2bongle2") );
1976f0d9
LR
101
102 return 0;
103}