malloc 线程安全吗?

编程入门 行业动态 更新时间:2024-10-23 16:21:36
本文介绍了malloc 线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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 线程安全吗?

本文发布于:2023-11-25 18:56:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630940.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   malloc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!