Malloc thread safe and compiler versions
Ian Lance Taylor
iant@google.com
Tue Jan 4 15:25:00 GMT 2011
"Brian D. McGrew" <brian@visionpro.com> writes:
> I just read on stackoverflow that if we compile with -pthreads, malloc is
> thread safe on x86 and x86_64 hardware. Is this true???
>
> If so, what version of gcc/g++ is that implemented in?
>
> We're using CentOS 5.3_x86-64 and gcc-4.1.2-20080704 and about 90% of our
> projects are compiled with g++ using -g -O2. Functionally speaking, is
> there any reason I should upgrade gcc --- other than just to have the latest
> version?
It's not true, at least not for GNU/Linux. malloc is thread safe on
GNU/Linux regardless of whether you use -pthread or not. In any case,
it's really a function of your version of glibc rather than a function
of your gcc. That is, you should be asking which version of glibc
provides a thread-safe malloc, not which version of gcc. And the answer
in your case is that the version of glibc you are using has a
thread-safe malloc.
Ian
More information about the Gcc-help
mailing list