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 8755479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:52:07+00:00 2026-06-13T13:52:07+00:00

Here is the scenario: 1) using an unordered_map<int, vector<MyClass*>*> let’s say I add keys

  • 0

Here is the scenario:

1) using an unordered_map<int, vector<MyClass*>*> let’s say I add keys 1, 2, … 8
2) all keys are set with a vector at program initialization and nothing more is added or deleted
3) I have 8 threads, where thread1 accesses key[1], thread2 accesses key[2], … thread8 accesses key[8] (i.e. the thread number can only access that key number and no other key)

Sometimes I re-assign the value vector* to another heap allocated collection. (i.e. thread1 performs key[1] = new vector<MyClass*>)

I believe this will be thread safe, am I correct? If not, I suppose I will use concurrent_unordered_map.

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-13T13:52:08+00:00Added an answer on June 13, 2026 at 1:52 pm

    The answer to this question can be found in [res.on.data.races]/3:

    A C++ standard library function shall not directly or indirectly modify objects (1.10) accessible by threads other than the current thread unless the objects are accessed directly or indirectly via the function’s non- const arguments, including this.

    Furthermore, [container.requirements.dataraces]/1 states:

    For purposes of avoiding data races ([res.on.data.races]), implementations shall consider the following functions to be const: begin, end, rbegin, rend, front, back, data, find, lower_bound, upper_bound, equal_range, at and, except in associative or unordered associative containers, operator[].

    Since unordered_map::operator[] is non-const, it is legal for an implementation to modify the unordered_map when a call to operator[] occurs. You should instead use unordered_map::find, which is explicitly required to be treated as const, and hence will not modify the unordered_map:

    map.find(key)->second = new vector<MyClass*>;
    

    (As a side note, your suggested design looks like a recipe for memory leaks. Why not make it be a unordered_map<int, std::unique_ptr<vector<MyClass*>>>, or unordered_map<int,vector<MyClass*>>?)

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

Sidebar

Related Questions

Let me try to set the scenario here first. This is done using ASP.NET
I am using backbone.js here is my scenario Lets say I have a view
Here is my scenario: I'm using nhibernate, openning and closing the session in an
Here's the scenario. I'm using a url rewriter that allows me to specify patterns
I'm having trouble using the new async/await tools in c#. Here is my scenario:
Here is my scenario. I am using Quicktest Pro (VB) to create an ActiveX
Here's my scenario: I'm using the WebBrowser control in a WinForms app to display
Here is my scenario: I am building a location finder using the iPhone mapkit.
I'm using Translate behavior. Here's the scenario: I save a translation on model 'Content'
This is probably a java noob question but here is my scenario: using selenium,

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.