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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:38:02+00:00 2026-05-26T21:38:02+00:00

I have a Concurrency::concurrent_vector and want to push_back thread safe a new element only

  • 0

I have a Concurrency::concurrent_vector and want to push_back thread safe a new element only in case it not already exists (that’s why I have to perform a search first). How can I accomplish this ?
I need a concurrent collection that it’s thread safe at iterator access(write,read same element) and also permits what I wrote above.

Question refinement:
What would be the best container to use if it’s mostly searched concurrently, if element is not found (more rare) an insert/push_back would be needed and in case search element is found (most of the cases) update to an element is needed (concurrent update of the same iterator)

From what is already available in VS2010 I saw concurrent_vector but that it is not safe at updating the same element and also it seems that I need an extra lock in case an element is not found and I need to add an element because of that. What do you think ? Is there something I can use to eliminate external locks (whole container locks)?

  • 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-05-26T21:38:03+00:00Added an answer on May 26, 2026 at 9:38 pm

    For the case described probably the best would be to use (from Visual Studio) the concurrent_unordered_map container which is a hash based container that ensures concurrent iteration, iterator access (as long as the updates/reads to the same element value is synchronized!), push_back-s, element access based on key (operator []).

    The container implementation is available as part of the Concurrency Runtime Sample Pack
    In case look-up by key is not necessary one could also use other concurrent containers:
    http://msdn.microsoft.com/en-us/library/dd504906.aspx

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

Sidebar

Related Questions

It is usually noted that simple database systems which does not have server (e.g.
I have a producer/consumer concurrency problem that I'm working on. The problem is that
I have read Java Concurrency in Practice and this is a great reference, but
Have you any problems using it on high concurrency environment? It's really works as
I have a multithreaded application that has many concurrent operations going on at once.
I have a problem with using Twisted for simple concurrency in python. The problem
We have multiple threads calling add(obj) on an ArrayList . My theory is that
I have a website that is being served by nginx and django. My staging.py
I have a servlet that does some work for user and then decrement user's
I have to code an Stateless EJB3 that uses callable statements, and builds a

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.