malloc() 函数是否可重入?
推荐答案我在某处读到,如果您使用 -pthread 进行编译,malloc 将成为线程安全的.我很确定它的实现依赖,因为 malloc 是 ANSI C 而线程不是.
I read somewhere that if you compile with -pthread, malloc becomes thread safe. I´m pretty sure its implementation dependant though, since malloc is ANSI C and threads are not.
如果我们在谈论 gcc:
If we are talking gcc:
编译和链接 -pthread 和malloc() 将是线程安全的,在 x86 上和 AMD64.
Compile and link with -pthread and malloc() will be thread-safe, on x86 and AMD64.
groups.google/group/comp.lang.c.moderated/browse_thread/thread/2431a99b9bdcef11/ea800579e40f7fa4
另一种观点,更有见地
{malloc, calloc, realloc, free,glibc-2.2+ 的 posix_memalign} 是线程安全
{malloc, calloc, realloc, free, posix_memalign} of glibc-2.2+ are thread safe
linux.derkeiler/Newsgroups/comp.os.linux.development.apps/2005-07/0323.html
更多推荐
malloc 线程安全吗?
发布评论