As far as I know, the C standard is silent about the thread-safety of malloc and free (and anything else concerning threads, for that matter.)
I've developed a lot of multithreaded programs using POSIX threads, and I have never had a problem with malloc/free. So I assume that on my implementation malloc/free are thread safe. (I'm using GCC 4.1.2 on Linux Debian 4)
However, I've read complaints on the Internet about random crashes with multi-threaded programs that use malloc/free.
So, is the use of mutexes in combination with malloc/free a requirement for writing portable code? I never use mutexes for malloc/free, so I fear porting my code to other platforms/compilers may require a bit of work.
Start Free Trial