Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一张看起来像这样的地图:std::map<int, class A*> m. 我有两个线程:一个是读取m和更新包含的对象的值,另一个是读取和写入(删除元素)。有没有办法在不使用互斥锁的情况下使其成为线程安全的?
std::map<int, class A*> m
m
有没有办法在不使用互斥锁的情况下使其成为线程安全的?
不。
您也许可以编写自己的无锁映射,也许有这样的想法,或者尝试这样的第三方库,但标准映射不提供线程安全保证。