]>
Commit | Line | Data |
---|---|---|
1976f0d9 LR |
1 | // 2003-05-03 Loren J. Rittle <rittle@labs.mot.com> <ljrittle@acm.org> |
2 | // | |
f90e600a | 3 | // Copyright (C) 2003, 2004 Free Software Foundation, Inc. |
1976f0d9 LR |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
8 | // Free Software Foundation; either version 2, or (at your option) | |
9 | // any later version. | |
10 | // | |
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | // | |
16 | // You should have received a copy of the GNU General Public License along | |
17 | // with this library; see the file COPYING. If not, write to the Free | |
18 | // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
19 | // USA. | |
20 | ||
515aab7c | 21 | // { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* } } |
2aa89cbb PC |
22 | // { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* } } |
23 | // { dg-options "-pthreads" { target *-*-solaris* } } | |
1976f0d9 LR |
24 | |
25 | #include <ext/rope> | |
26 | #include <cstring> | |
27 | #include <testsuite_hooks.h> | |
28 | ||
29 | // Do not include <pthread.h> explicitly; if threads are properly | |
30 | // configured for the port, then it is picked up free from STL headers. | |
31 | ||
32 | #if __GTHREADS | |
33 | ||
34 | const int max_thread_count = 4; | |
35 | const int max_loop_count = 10000; | |
36 | ||
63041e68 | 37 | __gnu_cxx::crope foo2; |
1976f0d9 LR |
38 | __gnu_cxx::crope foo4; |
39 | ||
11f10e6b | 40 | void* thread_main(void *) |
1976f0d9 LR |
41 | { |
42 | // To see a problem with gcc 3.3 and before, set a break point here. | |
43 | // Single step through c_str implementation, call sched_yield after | |
44 | // capture of NULL __old_c_string in any thread. Single step | |
45 | // through another thread past that same point. Now, one thread | |
46 | // will receive a bad pointer return. Adding dummy sched_yield | |
47 | // should never change program semantics under POSIX threads. | |
48 | const char* data4 = foo4.c_str(); | |
49 | ||
50 | // Please note that the memory leak in the rope implementation with | |
51 | // this test case, existed before and after fixing this bug... | |
11f10e6b | 52 | bool test __attribute__((unused)) = true; |
1976f0d9 | 53 | VERIFY( !std::strcmp (data4, "barbazbonglehellohellohello") ); |
11f10e6b | 54 | return 0; |
1976f0d9 LR |
55 | } |
56 | ||
f90e600a BK |
57 | #if !__GXX_WEAK__ && _MT_ALLOCATOR_H |
58 | // Explicitly instantiate for systems with no COMDAT or weak support. | |
59 | template class __gnu_cxx::__mt_alloc<__gnu_cxx::_Rope_RopeLeaf<char, std::allocator<char> > >; | |
60 | template class __gnu_cxx::__mt_alloc<__gnu_cxx::_Rope_RopeFunction<char, std::allocator<char> > >; | |
61 | template class __gnu_cxx::__mt_alloc<__gnu_cxx::_Rope_RopeSubstring<char, std::allocator<char> > >; | |
62 | template class __gnu_cxx::__mt_alloc<__gnu_cxx::_Rope_RopeConcatenation<char, std::allocator<char> > >; | |
63 | #endif | |
64 | ||
1976f0d9 LR |
65 | int |
66 | main() | |
67 | { | |
11f10e6b BK |
68 | bool test __attribute__((unused)) = true; |
69 | ||
1976f0d9 LR |
70 | pthread_t tid[max_thread_count]; |
71 | ||
72 | #if defined(__sun) && defined(__svr4__) | |
73 | pthread_setconcurrency (max_thread_count); | |
74 | #endif | |
75 | ||
76 | __gnu_cxx::crope foo; | |
77 | foo += "bar"; | |
78 | foo += "baz"; | |
79 | foo += "bongle"; | |
80 | const char* data = foo.c_str(); | |
81 | VERIFY( !std::strcmp (data, "barbazbongle") ); | |
82 | ||
83 | const char* data2; | |
84 | { | |
1976f0d9 LR |
85 | foo2 += "bar2"; |
86 | foo2 += "baz2"; | |
87 | foo2 += "bongle2"; | |
88 | data2 = foo2.c_str(); | |
89 | VERIFY( !std::strcmp (data2, "bar2baz2bongle2") ); | |
90 | } | |
91 | ||
92 | __gnu_cxx::crope foo3 ("hello"); | |
93 | const char* data3 = foo3.c_str(); | |
94 | VERIFY( !std::strcmp (data3, "hello") ); | |
95 | ||
96 | for (int j = 0; j < max_loop_count; j++) | |
97 | { | |
98 | foo4 = foo; | |
99 | foo4 += foo3; | |
100 | foo4 += foo3; | |
101 | foo4 += foo3; | |
102 | ||
103 | for (int i = 0; i < max_thread_count; i++) | |
104 | pthread_create (&tid[i], NULL, thread_main, 0); | |
105 | ||
106 | for (int i = 0; i < max_thread_count; i++) | |
107 | pthread_join (tid[i], NULL); | |
108 | } | |
109 | ||
63041e68 PC |
110 | VERIFY( !std::strcmp (data, "barbazbongle") ); |
111 | VERIFY( !std::strcmp (data2, "bar2baz2bongle2") ); | |
1976f0d9 LR |
112 | |
113 | return 0; | |
114 | } | |
115 | #else | |
116 | int main (void) {} | |
117 | #endif |