This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Malloc thread safe and compiler versions
- From: Ian Lance Taylor <iant at google dot com>
- To: "Brian D. McGrew" <brian at visionpro dot com>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: Tue, 04 Jan 2011 07:24:54 -0800
- Subject: Re: Malloc thread safe and compiler versions
- References: <C94878C4.441E1%brian@visionpro.com>
"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