STL / MySQL / __USE_MALLOC

stefan@noname4us.com stefan@noname4us.com
Fri Oct 26 02:20:00 GMT 2001


Hi!

We are developing a MT server based on the pthreads library on Linux (2.4.12).

The basic setup is: Main loop does accept(), push_back socketdescr to vector,
picked up by workers, workers can cache their results into a global hash_map

We are compiling using GCC 3.0.1 (which seems to conform great to the ISO, nice 
work!).

Compiling using default (only -pthread -lpthread) gives no warnings, and the
server will run perfectly with one connection. As soon as two threads are 
working we seem to get some kind of "race condition" for allocating memory and 
the application runs painfully slow...
...recompiling using __USE_MALLOC seems to work at first, but since we do lot's 
of insert/delete's in the hash_map we seem to fragment the memory to the point 
that it crashes.

Next issue is related to freeing memory, using __USE_MALLOC we seem to get a 
memory leak (of if this is related to memory fragmentation, I'm not sure) which 
over time bogs down the server...

Since the server is mainly STL code and we have successfully developed 
applications purely on STL before it seems like we have "found a way" to get 
multiple memory allocator into the same application, that's why i mentioned 
MySQL in the subject - this is the only other linked library that we know will 
allocate memory.

Thanks in advance!

/Stefan



More information about the Libstdc++ mailing list