Thank you all for the replies.

The code compiled correctly and runs perfectly. Memory allocation has to be thread safe. No switch was necessary.

Regards,
Panagiotis

On Thu, Apr 14, 2011 at 1:54 PM, John Maddock <boost.regex@virgin.net> wrote:
I am using boost::threads for an application that allocates space in heap with the new operator. Therefore,  different threads allocate memory in parallel. Do I have to link my application to any other library apart from the libboost_thread to guarantee a thread safe memory allocation?
I searched online, but I got more confused. Do I have to define the -D_REENTRANT or the -pthread symbol?

Somebody else could probably provide a much better and much completer
answer, but here's what I think I know. Perhaps you already found the
answer in the meanwhile...

Whether memory allocation is thread-safe depends on your allocator. If
you didn't explicitly specify the allocator you'll be using
std::allocator<yourType>. IIRC, that allocator is thread-safe so you
don't need to worry about additional compiler flags (as far as memory
allocation is concerned).

Maybe, the answer depends entirely on the compiler and platform you're on, but if Boost.Thread thinks your compiler is in multithreading-mode (i.e. your code using Boost.Thread compiles OK), then you should be fine.

John.
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users