Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8405635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:53:41+00:00 2026-06-09T22:53:41+00:00

I am using a boost::unordered_map<const std::string, std::list<TypeA> > in a performance critical multi-threaded environment.

  • 0

I am using a boost::unordered_map<const std::string, std::list<TypeA> > in a performance critical multi-threaded environment. I understand that writing to STL containers isn’t thread safe and the same goes for boost::unordered_map.

boost::unordered_map<const std::string, std::list<TypeA> > myMap;
// Added some elements to myMap        

Now, if I want to add or delete an element of type A to the list as , is it necessary is I just lock the entire map as opposed to locking the list that is being modified so that other threads can read/write the rest of the key value pairs?

// 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 

What if the list is replaced by another STL container?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:53:42+00:00Added an answer on June 9, 2026 at 10:53 pm

    Since you’re modifying only the contained object, not the [unordered_]map itself, you should only have to lock that contained object. If you change the list to another sequence (e.g., deque or vector) the same should remain true — changing the type of the contained object doesn’t change the fact that you’re only modifying that contained object, not the map that contains it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using boost uuid to generate session ids. std::string SessionGenerator::generate() { boost::uuids::uuid id =
I have the following code: #include <iostream> #include boost/unordered_map.hpp using namespace std; using namespace
When using BOOST_FOREACH , is the following code safe? BOOST_FOREACH (const std::string& str, getStrings())
Using Boost 1_33_1, I get an error implying that my iterator is a const
I have defined a Map boost::unordered_map<std::string,std::string>m_mapABC ; And I Store values in it Like
I've been using Boost::regex and Boost::regex_search and found that when I run the regex
I tried to switch from std::unordered_map (VS2010) to boost::unordered_map (version 1.48) and surprisingly, some
If I understand it correctly, both std::map and std::unordered_map store keys explicitely (store pairs
I want to define std::tr1::hash<boost::tuple<A,B,C> > . But I get an error that doesn't
I am changing a single thread program into multi thread using boost:thread library. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.