是C ++的新操作符可重入(或异步安全)? [英] Is C++'s new operator reentrant (or async-safe)?

查看:123
本文介绍了是C ++的新操作符可重入(或异步安全)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景在我的这个问题中。很简单,我必须在多线程C ++程序中 fork ,所以我想知道当限制为可重入时,我能做多少

The background is in this question of mine. Put shortly, I have to fork in a multithreaded C++ program, so I'd like to figure out how much I can do when restricted to reentrant functions only, and one of the most essential things is dynamic memory.

所以, malloc 已知是不可重入。但是C ++的 new 呢?我搜索的结果不多,主要是由于难以找到正确的新),但至少有一个声称 new 可重入。还有一个关于整个C ++标准库的相关问题,没有满意的答案。

So, malloc is known to be non-reentrant. But what about C++'s new? I googled for that with not many relevant results (mostly due to the difficulty to hit the correct "new"), but there is at least one claim that new is reentrant. There is also a relevant question concerning the whole C++ standard library with no satisfying answer.

编辑:我想标准没有说什么,所以我最关心的主要实现。

I guess the standard didn't say anything about this, so I'm mostly concerned about major implementations.

推荐答案

我已查看过 gcc libsupc ++ clang libc ++ 源代替符合标准的C ++ new / delete操作符 - 支持在 malloc不能保证的平台上的本地SIMD对齐要求

I've looked at both the gcc libsupc++ and clang libc++ source, for replacing the standard-conforming C++ new/delete operators - to support native SIMD alignment requirements on platforms where it wasn't guaranteed by malloc.

它们基本上是 malloc 免费一些EH逻辑等。我不是一个语言律师,但除非两个都错了,我认为可以得出结论:不,他们不可重入。

They are basically wrappers for malloc and free with some EH logic, etc. I am not a language lawyer, but unless both have it wrong, I think it's safe to conclude: no, they are not reentrant.

这篇关于是C ++的新操作符可重入(或异步安全)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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