是的malloc线程安全的? [英] Is malloc thread-safe?

查看:691
本文介绍了是的malloc线程安全的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的malloc()函数重入?

推荐答案

我读的地方,如果你有-pthreads编译,malloc的变成线程安全的。 I'm pretty确保它的实现依赖虽然,因为的malloc是ANSI C和线程不是。

I read somewhere that if you compile with -pthreads, 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:

编译和链接-pthreads和
  的malloc()将是线程安全的,在x86
  和AMD64。

Compile and link with -pthreads and malloc() will be thread-safe, on x86 and AMD64.

<一个href=\"http://groups.google.com/group/comp.lang.c.moderated/browse%5Fthread/thread/2431a99b9bdcef11/ea800579e40f7fa4\">http://groups.google.com/group/comp.lang.c.moderated/browse_thread/thread/2431a99b9bdcef11/ea800579e40f7fa4

另一种意见认为,更具洞察力

Another opinion, more insightful

{malloc的,释放calloc,realloc的,免费的,
  posix_memalign}的glibc的-2.2 +是
  线程安全的。

{malloc, calloc, realloc, free, posix_memalign} of glibc-2.2+ are thread safe

<一个href=\"http://linux.derkeiler.com/Newsgroups/comp.os.linux.development.apps/2005-07/0323.html\">http://linux.derkeiler.com/Newsgroups/comp.os.linux.development.apps/2005-07/0323.html

这篇关于是的malloc线程安全的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆