boost::unordered_map<const std::string, std::list<TypeA> >
パフォーマンスが重要なマルチスレッド環境でを使用しています。STL コンテナーへの書き込みはスレッド セーフではないことを理解していますboost::unordered_map
。
boost::unordered_map<const std::string, std::list<TypeA> > myMap;
// Added some elements to myMap
ここで、タイプ A の要素を としてリストに追加または削除する場合、他のスレッドが残りの部分を読み書きできるように、変更中のリストをロックするのではなく、マップ全体をロックする必要がありますか?キーと値のペア?
// Assuming there are pair with the keys "Apple" and "Orange" in myMap
A a, b;
myMap["Orange"].push_back(a) //Add an element to the list
myMap["Apple"].remove(b); //Remove an element
リストが別の STL コンテナーに置き換えられた場合はどうなるでしょうか。
ありがとう。