Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. STL hashmap crashing

STL hashmap crashing

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++databasecryptographyquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Subrat Patnaik
    wrote on last edited by
    #1

    hi all, i have a service application, which maintains a record of each and every USB being used in the windows system. in brief, my problem is with the hashmap values getting corrupted in between two threads. one thread picks the database path where values are to be written and other thread writes into that database path. Service crashes at the, when the below codes are executed. WaitForSingleObject(*hThreadIterBegin->second,INFINITE); rename(hThreadIterBegin->first->c_str(),newFileName.c_str()); ReleaseMutex(*hThreadIterBegin->second); The first thread fetches the values and the values are sent to the second thread so that it can write the necessary things to the fetched value which is the path of the database. but the hashmap value crashes at some point due to which the service crahses at above code executions. i am not able to identify the exact reason, as to why the value of ThreadMutexMapPrimary changes or crashes when it is called from the second thread??? i am attaching the code below, with declarations and values i received while debugging. Thankyou.

    **************************

    Variable declarations


    cahr queryFile[256];

    string queryFileString;

    int currentMap;

    hash_map ThreadMutexMapPrimary;

    hash_map ::iterator hThreadIterBegin;

    hash_map ::iterator hThreadIterEnd;

    **************************

    **********************************************************************************************

    FUNCTION CALL


    In 1st Thread:-> For fetching

    string queryFileString = queryFile;

    HANDLE presentMutex = CreateMutex(NULL,FALSE,NULL);
    
    if(presentMutex == NULL)
    
    {
    
    	WriteLog("Error Creating Mutex");
    
    }
    
    else
    
    	if(currentMap == 1)
    
    		ThreadMutexMapPrimary.insert(hash\_map ::value\_type(&queryFileString,&presentMutex));
    
    	else
    
    		ThreadMutexMapSecondary.insert(hash\_map ::value\_type(&queryFileString,&presentMutex));
    

    In 2nd Thread:-> For writing values

    switch(currentMap)

    	{
    
    	case 1:
    
    		if(ThreadMutexMapPrimary.empty())
    
    		{
    
    			WriteLog("Hash Map Empty No record to Write");
    
    			break;
    
    		}
    
    		hThreadIterBegin =  ThreadMutexMapPrimary.begin();
    
    		hThreadIterEnd = ThreadMutexMapPrimary.end();
    
    		currentMap = 2;
    
    		currentMappingSetReplaced = true;
    
    		break;
    
    	case 2:
    
    		if(Thre
    
    R 1 Reply Last reply
    0
    • S Subrat Patnaik

      hi all, i have a service application, which maintains a record of each and every USB being used in the windows system. in brief, my problem is with the hashmap values getting corrupted in between two threads. one thread picks the database path where values are to be written and other thread writes into that database path. Service crashes at the, when the below codes are executed. WaitForSingleObject(*hThreadIterBegin->second,INFINITE); rename(hThreadIterBegin->first->c_str(),newFileName.c_str()); ReleaseMutex(*hThreadIterBegin->second); The first thread fetches the values and the values are sent to the second thread so that it can write the necessary things to the fetched value which is the path of the database. but the hashmap value crashes at some point due to which the service crahses at above code executions. i am not able to identify the exact reason, as to why the value of ThreadMutexMapPrimary changes or crashes when it is called from the second thread??? i am attaching the code below, with declarations and values i received while debugging. Thankyou.

      **************************

      Variable declarations


      cahr queryFile[256];

      string queryFileString;

      int currentMap;

      hash_map ThreadMutexMapPrimary;

      hash_map ::iterator hThreadIterBegin;

      hash_map ::iterator hThreadIterEnd;

      **************************

      **********************************************************************************************

      FUNCTION CALL


      In 1st Thread:-> For fetching

      string queryFileString = queryFile;

      HANDLE presentMutex = CreateMutex(NULL,FALSE,NULL);
      
      if(presentMutex == NULL)
      
      {
      
      	WriteLog("Error Creating Mutex");
      
      }
      
      else
      
      	if(currentMap == 1)
      
      		ThreadMutexMapPrimary.insert(hash\_map ::value\_type(&queryFileString,&presentMutex));
      
      	else
      
      		ThreadMutexMapSecondary.insert(hash\_map ::value\_type(&queryFileString,&presentMutex));
      

      In 2nd Thread:-> For writing values

      switch(currentMap)

      	{
      
      	case 1:
      
      		if(ThreadMutexMapPrimary.empty())
      
      		{
      
      			WriteLog("Hash Map Empty No record to Write");
      
      			break;
      
      		}
      
      		hThreadIterBegin =  ThreadMutexMapPrimary.begin();
      
      		hThreadIterEnd = ThreadMutexMapPrimary.end();
      
      		currentMap = 2;
      
      		currentMappingSetReplaced = true;
      
      		break;
      
      	case 2:
      
      		if(Thre
      
      R Offline
      R Offline
      Roger Allen
      wrote on last edited by
      #2

      Your problem seems to possibly be related to an issue we saw in our own software. Switching to an alternate STL provider fixed our issues. See http://support.microsoft.com/kb/813810[^] You may well be being affected by this. BTW we switched to STLport a free STL implementation.

      If you vote me down, my score will only get lower

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups