This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Memory allocators / STL
- To: Loren James Rittle <rittle at latour dot rsch dot comm dot mot dot com>
- Subject: Re: Memory allocators / STL
- From: Benjamin Kosnik <bkoz at redhat dot com>
- Date: Tue, 30 Oct 2001 00:04:15 -0800 (PST)
- cc: libstdc++ at gcc dot gnu dot org
> > There have been problems with using the pool allocators in a multithreaded
> > program; I've pointed you at an internal bug report (102997) about that a
> > couple of times. I would think the test case from there should work for
> > you. I was able to reproduce the bug on schitzo.
Huh.
> > Of course, that bug report is against a 2.95ish toolchain, so the problems
> > may have been fixed by now.
I tried it with gcc-3.1, on a dual RH 7.1 machine. It's fine. This is
with the pool-alloc allocators.
Perhaps it's dual solaris 2.6, 2.95.x problem, or the older library.
> If I can get access to this ``internal bug report (102997)'', then I
> would be happy to fix mainline gcc if the problem still exists there
> and I can reproduce it in my environment(s). But I only want the test
> case if it is something that can be publicly posted.
Right.
This testcase works now, but perhaps it can be modified into the unposted
problem with mySQL, etc.
// Compile with:
// g++ -g -D_THREAD_SAFE -DSOLARIS -D_REENTRANT -D_PTHREADS -o \
// bad_hash bad_hash.cpp -lpthread
// Causes a core dump in the first few iterations under Solaris 2.6
// egcs 2.91.66 or Cygnus 98r2, STL library included with the
// respective distributions.
// The core dump does not happen with NUM_THREADS=1, and happens more
// quickly the higher the value for NUM_THREADS.
// There is no core dump if std::map is used instead of
// std::hash_map, or if types other than string are used
// for the map's value type (int, char*, vector do not cause
// the core dump).
//
// John Panzer
// jpanzer@netscape.com
#include <cstdio>
#include <cstdlib>
#include <sys/poll.h>
#include <string>
#include <ext/hash_map>
#include <pthread.h>
using namespace std;
const int NUM_ITERATIONS=500000;
void *f(void *arg)
{
for(int i = 0; i < NUM_ITERATIONS; ++i)
{
hash_map<int, string> m;
m[42] = "foobar";
poll(0, 0, 10);
}
}
void mt_test()
{
const int NUM_THREADS = 20;
void* ret=0;
pthread_t thread[NUM_THREADS];
for(int i=0;i<NUM_THREADS;++i)
pthread_create(&thread[i], NULL, f, (void*)i);
for(int i=0 ; i < NUM_THREADS; ++i)
pthread_join(thread[i], &ret);
}
int main()
{
mt_test();
return 0;
}