gpt4 book ai didi

c++ - 使用静态映射和 std::make_pair 的地址处的 KERN_PROTECTION_FAILURE

转载 作者:行者123 更新时间:2023-11-28 02:52:45 26 4
gpt4 key购买 nike

我收到这个错误

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0xb064425c

调用以下函数时:

const std::map<FunctionID, std::string> getEnumElementsStringRepresentation() {
static bool is_initialized = false;
static std::map<FunctionID, std::string> enum_string_representation; // Fails here
if (false == is_initialized) {
enum_string_representation.insert(std::make_pair(FunctionID.capabilities, "capabilities"));
... many more similar inserts
is_initialized = true;
}
return enum_string_representation;
}

这似乎是一个读/写错误,但我不确定调试的最佳方法。

最佳答案

你说你的代码是多线程的。由于函数静态 map 实例,getEnumElementsStringRepresentation 不可重入(通常)。您将不得不使用互斥锁来保护函数,或者使用线程本地存储。

关于c++ - 使用静态映射和 std::make_pair 的地址处的 KERN_PROTECTION_FAILURE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22673292/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com