2003-05-06 00:28:16 +02:00
|
|
|
// 2003-05-03 Loren J. Rittle <rittle@labs.mot.com> <ljrittle@acm.org>
|
|
|
|
//
|
2007-03-02 17:21:30 +01:00
|
|
|
// Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
|
2003-05-06 00:28:16 +02:00
|
|
|
//
|
|
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
|
|
// software; you can redistribute it and/or modify it under the
|
|
|
|
// terms of the GNU General Public License as published by the
|
|
|
|
// Free Software Foundation; either version 2, or (at your option)
|
|
|
|
// any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this library; see the file COPYING. If not, write to the Free
|
2005-08-17 04:28:44 +02:00
|
|
|
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
2003-05-06 00:28:16 +02:00
|
|
|
// USA.
|
|
|
|
|
2007-07-16 19:21:10 +02:00
|
|
|
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
|
|
|
|
// { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
|
2004-03-05 00:29:44 +01:00
|
|
|
// { dg-options "-pthreads" { target *-*-solaris* } }
|
2003-05-06 00:28:16 +02:00
|
|
|
|
|
|
|
#include <ext/rope>
|
|
|
|
#include <cstring>
|
2007-03-02 17:21:30 +01:00
|
|
|
#include <pthread.h>
|
2003-05-06 00:28:16 +02:00
|
|
|
#include <testsuite_hooks.h>
|
|
|
|
|
|
|
|
const int max_thread_count = 4;
|
|
|
|
const int max_loop_count = 10000;
|
|
|
|
|
2004-10-07 00:12:34 +02:00
|
|
|
typedef __gnu_cxx::rope<char, std::allocator<char> > rope_type;
|
|
|
|
rope_type foo2;
|
|
|
|
rope_type foo4;
|
2003-05-06 00:28:16 +02:00
|
|
|
|
2003-09-23 22:03:30 +02:00
|
|
|
void* thread_main(void *)
|
2003-05-06 00:28:16 +02:00
|
|
|
{
|
|
|
|
// To see a problem with gcc 3.3 and before, set a break point here.
|
|
|
|
// Single step through c_str implementation, call sched_yield after
|
|
|
|
// capture of NULL __old_c_string in any thread. Single step
|
|
|
|
// through another thread past that same point. Now, one thread
|
|
|
|
// will receive a bad pointer return. Adding dummy sched_yield
|
|
|
|
// should never change program semantics under POSIX threads.
|
|
|
|
const char* data4 = foo4.c_str();
|
|
|
|
|
|
|
|
// Please note that the memory leak in the rope implementation with
|
|
|
|
// this test case, existed before and after fixing this bug...
|
2003-09-23 22:03:30 +02:00
|
|
|
bool test __attribute__((unused)) = true;
|
2003-05-06 00:28:16 +02:00
|
|
|
VERIFY( !std::strcmp (data4, "barbazbonglehellohellohello") );
|
2003-09-23 22:03:30 +02:00
|
|
|
return 0;
|
2003-05-06 00:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
2003-09-23 22:03:30 +02:00
|
|
|
bool test __attribute__((unused)) = true;
|
|
|
|
|
2003-05-06 00:28:16 +02:00
|
|
|
pthread_t tid[max_thread_count];
|
|
|
|
|
2005-02-18 12:53:18 +01:00
|
|
|
#if defined(__sun) && defined(__svr4__) && _XOPEN_VERSION >= 500
|
2003-05-06 00:28:16 +02:00
|
|
|
pthread_setconcurrency (max_thread_count);
|
|
|
|
#endif
|
|
|
|
|
2004-10-07 00:12:34 +02:00
|
|
|
rope_type foo;
|
2003-05-06 00:28:16 +02:00
|
|
|
foo += "bar";
|
|
|
|
foo += "baz";
|
|
|
|
foo += "bongle";
|
|
|
|
const char* data = foo.c_str();
|
|
|
|
VERIFY( !std::strcmp (data, "barbazbongle") );
|
|
|
|
|
|
|
|
const char* data2;
|
|
|
|
{
|
|
|
|
foo2 += "bar2";
|
|
|
|
foo2 += "baz2";
|
|
|
|
foo2 += "bongle2";
|
|
|
|
data2 = foo2.c_str();
|
|
|
|
VERIFY( !std::strcmp (data2, "bar2baz2bongle2") );
|
|
|
|
}
|
|
|
|
|
2004-10-07 00:12:34 +02:00
|
|
|
rope_type foo3 ("hello");
|
2003-05-06 00:28:16 +02:00
|
|
|
const char* data3 = foo3.c_str();
|
|
|
|
VERIFY( !std::strcmp (data3, "hello") );
|
|
|
|
|
|
|
|
for (int j = 0; j < max_loop_count; j++)
|
|
|
|
{
|
|
|
|
foo4 = foo;
|
|
|
|
foo4 += foo3;
|
|
|
|
foo4 += foo3;
|
|
|
|
foo4 += foo3;
|
|
|
|
|
|
|
|
for (int i = 0; i < max_thread_count; i++)
|
|
|
|
pthread_create (&tid[i], NULL, thread_main, 0);
|
|
|
|
|
|
|
|
for (int i = 0; i < max_thread_count; i++)
|
|
|
|
pthread_join (tid[i], NULL);
|
|
|
|
}
|
|
|
|
|
2004-03-29 11:54:15 +02:00
|
|
|
VERIFY( !std::strcmp (data, "barbazbongle") );
|
|
|
|
VERIFY( !std::strcmp (data2, "bar2baz2bongle2") );
|
2003-05-06 00:28:16 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|