|
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.
*******************************************
|
|
|
|
|
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
|
|
|
|
|
[id(0x60060001), helpcontext(0x000061aa)]
HRESULT GetComponents([in, out] SAFEARRAY(VARIANT) oAxisComponentsArray);
I want to know how to realize the COM in C++ with InvokeHelper.
Thanks
|
|
|
|
|
In the IDL file it should be [in, out] SAFEARRAY(VARIANT)* oAxisComponentsArray
In the .h and .cpp files it should be SAFEARRAY** oAxisComponentsArray
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Superman,thanks a lot.
Could you please tell me how to realize the SAFEARRAY(VARIANT) oAxisComponentsArray with C++, and how to write InvokeHelper?
|
|
|
|
|
I record audio with several microphones and I need to know the microphone that I used with each recording.
Can anyone help me? How can I identify the microphone in the recording?
Is there a command or something like that?
Thank you
|
|
|
|
|
waveInGetDevCaps may help u..
Regards,
Swapnil
|
|
|
|
|
Hi,
I am facing a problem with IWshRuntimeLibrary::IFileSystem. It is working fine on Win2003,Vista 32 bit. But fails in Win2008 std sp2.
I am using following function from IWshRuntimeLibrary::IFileSystem
1.CopyFile
2.GetFolder
3.FileExists
4.DeleteFolder
5.CreateFolder
I am currently using VC++.
Why IWshRuntimeLibray::IFileSystem is failing. Can I have any alternate solution.
|
|
|
|
|
Please debug and check the reason for failure
but i have the alternate solution as to suggest you to use SDK APIs
CopyFile :: Copies an existing file to a new file.
CopyFileEx :: Copies an existing file to a new file.
CreateDirectory :: Creates a new directory.
CreateDirectoryEx :: Creates a new directory with the attributes of a specified template directory.
CreateFile :: Creates or opens a file object.
DeleteFile :: Deletes an existing file.
|
|
|
|
|
Hi all,
I m creating a Property Sheet with help of CPropertySheet class,in Property Pages i m using Groupbox i want make bold the text of groupbox please help me how can i do this.
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
This may not be an answer to your question, but the easiest way to do this is to place a picture control with a bitmap of the text with the required font size over the group box.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
You mean some text inside the groupbox or the caption of the groupbox? If the caption of the group box, you could rename the ID of the group box such that it is NOT IDC_STATIC and then add a control variable to it (say m_GroupBox ) and then call m_GroupBox.SetFont();
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
I m already try this but its not done.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
OK, try this code:
CFont f1;
LOGFONT lf1;
::ZeroMemory(&lf1, sizeof(lf1));
lf1.lfHeight = 16;
lf1.lfCharSet = ANSI_CHARSET;
lf1.lfWeight = FW_BOLD;
::lstrcpy(lf1.lfFaceName, "Arial");
f1.CreateFontIndirect(&lf1);
GetDlgItem(IDC_GROUPBOX)->SetFont(&f1);
f1.Detach();
Obviously you'll have to change some things to make it work with your code but you'll get the idea.
Edit:
Actually, you might want to clarify first what Rajesh asked:
You mean some text inside the groupbox or the caption of the groupbox?
modified on Friday, July 24, 2009 5:25 AM
|
|
|
|
|
I mean the caption of groupbox.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
OK, then try the code above.
|
|
|
|
|
"_$h@nky_" wrote: I m already try this but its not done.
Like... What did you try? Show the code.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh R Subramanian wrote: Show the code
Yes, sir.
|
|
|
|
|
Hi all,
In my program, I have the following statement:
ISearchResultPtr spIsr = spWuSearcher->Search(criteria);
Most of time, the program will excute successfully, but when "criteria" is _T("UpdateID='12345678-9abc-def0-1234-56789abcdef0'"), then spIsr->Updates->Count is 0, but not 1 which is the right value.
Is there anyone who knows why or when this happens?
NOTE: I'm sure the "UpdateID" is right.
Any reply is appreciated.
Thanks a lot
|
|
|
|
|
Is there any way to find out which logical drive is in use by windows or is opened in Explorer in C++ ?
Thanks,
Kushagra
I hate coding but I love to develop
|
|
|
|
|
|
Actually ,
I wanted to know if that logical drive is opened in explorer even if no file inside is in use. It can happen that we have just opened C:\ drive in explorer but we are'nt using any folder inside C:\ but still that drive remains open ...can you help me for this specific case too
Thanks,
Kushagra
I hate coding but I love to develop
|
|
|
|
|
Kindly help me out in this...
Regards,
Kushagra
|
|
|
|
|
If my pointer is pointing an invalid object. How to find proactively in run-time.
|
|
|
|
|
there are some memory check functions as _CrtIsValidPointer()
It is strongly recommanded to avoid this situation. use pointers to data, only for copying the data, if you need it later. -> make your own object
Press F1 for help or google it.
Greetings from Germany
|
|
|
|