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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:15:18+00:00 2026-06-01T12:15:18+00:00

unordered_map<std::string,unordered_map<std::string, std::string> >* storing_vars; I have this variable in the scope declared in the

  • 0
unordered_map<std::string,unordered_map<std::string, std::string> >* storing_vars;

I have this variable in the scope declared in the scope.

This is declared in the constructor.

this->storing_vars =  new unordered_map<std::string,unordered_map<std::string, std::string> >();

in order to initialize it.

Then what I do is call a function over and over again by my BackgroundWorker

for(int i2 = 0; i2 < 30; i2++){



                int index_pos_curr = i2;


                //Start the Threads HERE


                this->backgroundWorker2 = gcnew System::ComponentModel::BackgroundWorker;
                this->backgroundWorker2->WorkerReportsProgress = true;
                this->backgroundWorker2->WorkerSupportsCancellation = true;


                //this->backgroundWorker2->FieldSetter(L"std::string",L"test","damnnit");

                backgroundWorker2->DoWork += gcnew DoWorkEventHandler( this, &MainFacebook::backgroundWorker2_DoWork );
                backgroundWorker2->RunWorkerCompleted += gcnew RunWorkerCompletedEventHandler( this, &MainFacebook::backgroundWorker2_RunWorkerCompleted );
                backgroundWorker2->ProgressChanged += gcnew ProgressChangedEventHandler( this, &MainFacebook::backgroundWorker2_ProgressChanged );
                backgroundWorker2->RunWorkerAsync(index_pos_curr);
                Sleep(50); //THE PROBLEM IS HERE, IF I COMMENT THIS OUT it won't work, that's probably because there are a lot of functions trying to add values in the same variable (even though the indexes are differents in each call)
            }

After this is done it calls the DoWork Function

void backgroundWorker2_DoWork(Object^ sender, DoWorkEventArgs^ e ){
             BackgroundWorker^ worker = dynamic_cast<BackgroundWorker^>(sender);         
             e->Result = SendThem( safe_cast<Int32>(e->Argument), worker, e );          

        }

int SendThem(int index){

            stringstream st;
            st << index;

            //...
            (*this->storing_vars)[st.str()]["index"] =  "testing1";
            (*this->storing_vars)[st.str()]["rs"] = "testing2";
            return 0;
}

as I added the comment in the Sleep(50) line, I believe the problem is that since the thread in the background call the same function, it has a problem to store the data when it’s called a lot of times probably not even waiting for the other storing to finish, it’s causing an error in the “xhash.h” file, an error that is sanitized by using Sleep(50), but I can’t use those because it freezes my UI and also 50 miliseconds is the time I’m assuming it already stored the variable value, but what if it takes longer in slower computers? it’s not the right approach.

How do I do to fix that?

I want to be able to UPDATE the unordered_map WITHOUT the use of SLEEP

Thanks in advance.

  • 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-01T12:15:19+00:00Added an answer on June 1, 2026 at 12:15 pm

    After so many votes down I actually started to look for the Mutex, people were talking about here, after a while I find out that it’s really simple to use. and it’s the correct way as my fellows here told me. Thank you all for the help =D

    Here what I did, I just had to add

    //Declare the Mutex
    static Mutex^ mut = gcnew Mutex;
    
    //then inside the function called over and over again I used mutex
    mut->WaitOne();
    //Declare/Update the variables
    mut->ReleaseMutex();
    //Then I release it.
    

    It works perfectly, Thank you all for the helps and criticism. haha

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

Sidebar

Related Questions

unordered_map<std::string, std::string>* Accounts; I have this code up there to initialize from a pointer,
I Have a object which the following field : boost::unordered_map<std::string, std::shared_ptr<Foo> > m_liste_; I
I have the following code: #include <string> #include <iostream> #include <tr1/unordered_map> typedef std::tr1::unordered_map<unsigned long
suppose i have the following: boost::unordered_map< string , someValueType > map; someValueType& value =
class MyObject{ public: void testFunctionMap(){ std::unordered_map<std::string, std::function<void()> > functionMap; std::pair<std::string, std::function<void()> > myPair(print, std::bind(&MyObject::printSomeText,
I am trying to do the following: boost::unordered_map<boost::flyweight<std::string>, boost::flyweight<std::string> > map; boost::flyweight<std::string> foo(name); map[foo]
I have been trying to make a StringTable class that holds a simple unordered_map<string,
I have the following: #include<iostream> #include<unordered_map> #include<tuple> using namespace std; class CTest { //
Yesterday i tried to use std::unordered_map and this code confused me how much memory
consider this class: class baseController { /* Action handler array*/ std::unordered_map<unsigned int, baseController*> actionControllers;

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.