gpt4 book ai didi

c++ - 线程安全关联容器

转载 作者:行者123 更新时间:2023-11-30 01:59:09 24 4
gpt4 key购买 nike

我有一张看起来像这样的 map :std::map<int, class A*> m .我有两个线程:其中一个正在阅读 m并更新包含的对象的值,另一个是读取和写入(删除元素)。有没有办法在不使用互斥锁的情况下使其成为线程安全的?

最佳答案

Is there a way to make it thread-safe without using mutexes?

没有。

你也许可以写你自己的无锁映射,也许有类似 this 的想法,或尝试第三方库,如 this ,但标准映射不提供线程安全保证。

关于c++ - 线程安全关联容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16522410/

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