]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/ext/rope/pthread7-rope.cc
1 // 2003-05-03 Loren J. Rittle <rittle@labs.mot.com> <ljrittle@acm.org>
3 // Copyright (C) 2003-2020 Free Software Foundation, Inc.
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 3, or (at your option)
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
21 // { dg-options "-pthread" }
22 // { dg-require-effective-target pthread }
27 #include <testsuite_hooks.h>
29 const int max_thread_count
= 4;
30 const int max_loop_count
= 10000;
32 typedef __gnu_cxx::rope
<char, std::allocator
<char> > rope_type
;
36 void* thread_main(void *)
38 // To see a problem with gcc 3.3 and before, set a break point here.
39 // Single step through c_str implementation, call sched_yield after
40 // capture of NULL __old_c_string in any thread. Single step
41 // through another thread past that same point. Now, one thread
42 // will receive a bad pointer return. Adding dummy sched_yield
43 // should never change program semantics under POSIX threads.
44 const char* data4
= foo4
.c_str();
46 // Please note that the memory leak in the rope implementation with
47 // this test case, existed before and after fixing this bug...
48 VERIFY( !std::strcmp (data4
, "barbazbonglehellohellohello") );
55 pthread_t tid
[max_thread_count
];
57 #if defined(__sun) && defined(__svr4__) && _XOPEN_VERSION >= 500
58 pthread_setconcurrency (max_thread_count
);
65 const char* data
= foo
.c_str();
66 VERIFY( !std::strcmp (data
, "barbazbongle") );
74 VERIFY( !std::strcmp (data2
, "bar2baz2bongle2") );
77 rope_type
foo3 ("hello");
78 const char* data3
= foo3
.c_str();
79 VERIFY( !std::strcmp (data3
, "hello") );
81 for (int j
= 0; j
< max_loop_count
; j
++)
88 for (int i
= 0; i
< max_thread_count
; i
++)
89 pthread_create (&tid
[i
], 0, thread_main
, 0);
91 for (int i
= 0; i
< max_thread_count
; i
++)
92 pthread_join (tid
[i
], 0);
95 VERIFY( !std::strcmp (data
, "barbazbongle") );
96 VERIFY( !std::strcmp (data2
, "bar2baz2bongle2") );