我目前正在使用Facebook 的并发哈希映射,我想知道这样的事情是否可行:
folly::ConcurrentHashMap<std::string, some_class> m;
// add some elements
const auto it = m.find("a");
// during this time, another thread removes the "a" element
if (it != m.end())
it->second.something(); // it is now an invalid iterator
在阅读了哈希图的来源之后,我遇到了这个:
迭代器持有指向返回元素的危险指针。元素只能在迭代器仍然有效时访问!
这很令人不安,感觉使用任何返回的迭代器都是不安全的,是这样吗?