|
Boost Users : |
Subject: Re: [Boost-users] [boost::threads] -D_REENTRANT?
From: John Maddock (boost.regex_at_[hidden])
Date: 2011-04-14 13:54:27
>> 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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net