Click here to Skip to main content
16,005,149 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionAdd-in Pin
john563224-Jul-09 1:32
john563224-Jul-09 1:32 
AnswerRe: Add-in Pin
Mahesh Kulkarni24-Jul-09 1:39
Mahesh Kulkarni24-Jul-09 1:39 
QuestionModelessDialog Pin
kumar sanghvi24-Jul-09 1:23
kumar sanghvi24-Jul-09 1:23 
AnswerRe: ModelessDialog Pin
«_Superman_»24-Jul-09 4:20
professional«_Superman_»24-Jul-09 4:20 
QuestionHow Can I detect silence? Pin
Guillermo198024-Jul-09 0:30
Guillermo198024-Jul-09 0:30 
AnswerRe: How Can I detect silence? Pin
Rozis24-Jul-09 13:42
Rozis24-Jul-09 13:42 
QuestionIServerXMLHTTPRequest setproxy() method usage Pin
Ash_VCPP24-Jul-09 0:09
Ash_VCPP24-Jul-09 0:09 
QuestionSTL hashmap crashing Pin
Subrat Patnaik24-Jul-09 0:09
Subrat Patnaik24-Jul-09 0:09 
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 <std::string*, HANDLE*> ThreadMutexMapPrimary;

hash_map <std::string*, HANDLE*>::iterator hThreadIterBegin;

hash_map <std::string*, HANDLE*>::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 <std::string*, HANDLE*>::value_type(&queryFileString,&presentMutex));

		else

			ThreadMutexMapSecondary.insert(hash_map <std::string*, HANDLE*>::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(ThreadMutexMapSecondary.empty())

			{

				WriteLog("Hash Map Empty No record to Write");

				break;

			}

			hThreadIterBegin =  ThreadMutexMapSecondary.begin();

			hThreadIterEnd = ThreadMutexMapSecondary.end();

			currentMap = 1;

			currentMappingSetReplaced = true;

			break;

		}



		DebugLog("after swtich(currentMap)");

		if(currentMappingSetReplaced == true)

		{

			while((hThreadIterBegin != hThreadIterEnd))

			{

				WriteLog("Beginning Database Archival System...\n");

				string parameter;

				string DatabaseName;

				remove(newFileName.c_str());

				

 				WaitForSingleObject(*hThreadIterBegin->second,INFINITE); ----> service crashes here

				

				rename(hThreadIterBegin->first->c_str(),newFileName.c_str()); ---

				

				ReleaseMutex(*hThreadIterBegin->second);



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



Debug Values:->

----------

value of queryFile -> "C:\windows\Logs\Tsql\Jul2009.sql"



value of queryFileString ->"C:\windows\Logs\Tsql\Jul2009.sql"



value of currentMap = 1





ThreadMutexMapPrimary -> [1](("C"\Windows\Logs\Tsql\Jul2009.sql",0x0201bae)) --> value in 1st thread



ThreadMutexMapPrimary -> [1]((0x0201ff74 {_Bx={...} _Mysize=??? _Myres=??? },0x0201bae)) -> value in second thread,changes and is crashed.



newFileName.c_str() -> "C:\windows\Logs\Tsql\Jul2009.sql";-----> to be deleted and new the value of thread mutex map to be inserted.





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

AnswerRe: STL hashmap crashing Pin
Roger Allen24-Jul-09 3:15
Roger Allen24-Jul-09 3:15 
QuestionHow to realize SAFEARRAY in C++ Pin
echo_yao24-Jul-09 0:03
echo_yao24-Jul-09 0:03 
AnswerRe: How to realize SAFEARRAY in C++ Pin
«_Superman_»24-Jul-09 4:08
professional«_Superman_»24-Jul-09 4:08 
GeneralRe: How to realize SAFEARRAY in C++ Pin
echo_yao26-Jul-09 16:25
echo_yao26-Jul-09 16:25 
QuestionHow to identify the microphone between several microphones Pin
Guillermo198023-Jul-09 23:52
Guillermo198023-Jul-09 23:52 
AnswerRe: How to identify the microphone between several microphones Pin
Swapnil Shah24-Jul-09 0:20
Swapnil Shah24-Jul-09 0:20 
QuestionCComPtr<iwshruntimelibrary::ifilesystem xmlns:iwshruntimelibrary="#unknown"> works fine in Win2003 and fails in Win2008 Std SP2</iwshruntimelibrary::ifilesystem> Pin
V K 223-Jul-09 23:14
V K 223-Jul-09 23:14 
AnswerRe: CComPtr works fine in Win2003 and fails in Win2008 Std SP2 Pin
Adam Roderick J24-Jul-09 1:33
Adam Roderick J24-Jul-09 1:33 
QuestionHow can make Group Box text bold in Property Sheet? Pin
Le@rner23-Jul-09 22:31
Le@rner23-Jul-09 22:31 
AnswerRe: How can make Group Box text bold in Property Sheet? Pin
«_Superman_»23-Jul-09 22:36
professional«_Superman_»23-Jul-09 22:36 
AnswerRe: How can make Group Box text bold in Property Sheet? Pin
Rajesh R Subramanian23-Jul-09 22:39
professionalRajesh R Subramanian23-Jul-09 22:39 
GeneralRe: How can make Group Box text bold in Property Sheet? Pin
Le@rner23-Jul-09 23:04
Le@rner23-Jul-09 23:04 
GeneralRe: How can make Group Box text bold in Property Sheet? [modified] Pin
Michael Schubert23-Jul-09 23:16
Michael Schubert23-Jul-09 23:16 
GeneralRe: How can make Group Box text bold in Property Sheet? Pin
Le@rner23-Jul-09 23:47
Le@rner23-Jul-09 23:47 
GeneralRe: How can make Group Box text bold in Property Sheet? Pin
Michael Schubert24-Jul-09 0:27
Michael Schubert24-Jul-09 0:27 
GeneralRe: How can make Group Box text bold in Property Sheet? Pin
Rajesh R Subramanian24-Jul-09 0:49
professionalRajesh R Subramanian24-Jul-09 0:49 
GeneralRe: How can make Group Box text bold in Property Sheet? Pin
Michael Schubert24-Jul-09 1:01
Michael Schubert24-Jul-09 1:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.