libstdc++ multi-threading: std::vector resize crash

Pavel Emeliyanenko
Fri Apr 20 13:14:00 GMT 2007

Hi all,

I have successfully investigated the bug. And it surprisingly has
nothing to deal with libstdc++. So, I should apologize for blaming libstdc++ :)
As turned out, this problem is related to "multi-threaded
programming with CORE and Gmp libraries".

Probably it is not the right place for such a discussion.
Nevertheless, I would like to discuss it here to make sure somebody
else will not fall into the same trap..

Unfortunately, CORE library ( is quite
poor documented and I didn't find in official sources any note that it
implicitly uses it's own memory pool (CORE::MemoryPool<T>). The memory
pool is installed by replacing "operator new" using macro definitions.

So, if this feature is turned on, the library is not thread-safe.
Moreover, the actual segfault occurs not in the CORE library but in
the underlying Gmp's mem-alloc function, such that it is hard to
investigate it.

To work-around this bug one needs to disable CORE's memory pool.
This is done by recompiling the library with CORE_DISABLE_MEMORY_POOL
flag defined either in CORE/Impl.h or as a compiler option.
(of course, one assumes that gmp library was properly configured with
--enable-alloca=malloc-reentrant option and so is libstdc++).

> I have the problem with libstdc++ memory allocation which I'm fighting against
> the last 2 weeks. Before writing directly to mailing list I tried to
> more or less thoroughly read through existent messages however this
> didn't help me a lot.

> The problem is the following: I work in EXACUS project and my server
> program should process multiple requests from clients (CGI-scripts)
> simultaneously. Without getting deeper into details, I pasted a piece
> of code where it crashes.

Best regards,

More information about the Libstdc++ mailing list