|
Call CloseHandle() when the process is done with the mutex such as right before the process terminates.
Kuphryn
|
|
|
|
|
Thanks, got it working, one other question, will the processing for protecting the data be under 100msec;
i.e. the time to:-
Create(m)
WaitForSingleObject(m)
ReleaseMutex(m)
I know is a very general question but an order of magnitude would be helpful.
I have a timer checking for new data, the rate could be 100msec to several seconds?
|
|
|
|
|
There is no need to create the mutex each time. Just create it once and close it when the process terminates or when it is no longer needed throughout the process lifetime.
Kuphryn
|
|
|
|
|
I am now confused!
If I create the Mutex, then when I go into my routine which I WaitForSingleObject, then I wait forever. This was my query.
But if I create it each time I go into my WaitForMutex routine, I get it; i.e. my program works. See updated WaitForMutex routine.
<big>bool WaitForMutex(void)<br />
{<br />
<br />
<br />
m_hMutex = ::CreateMutex(NULL,FALSE,"CSLSharedMemLock");<br />
if(m_hMutex)<br />
{<br />
if (::WaitForSingleObject(m_hMutex,INFINITE) == WAIT_OBJECT_0)<br />
{<br />
return true;<br />
ReleaseMutex(m_hMutex);<br />
}<br />
return false;<br />
}<br />
}</big>
My EXE uses CSLSharedMemLock for the Mutex and the libray (DLL) also uses CSLSharedMemLock as the Mutex name.
Sweep123 working from home!
grahamfff
|
|
|
|
|
Your EXE and DLL both need to call CreateMutex ,
hMutex = ::CreateMutex ( 0, FALSE, "CSLSharedMemLock" ) ;
Now nobody owns the mutex but everybody has a handle to it.
So when you need the mutex call,
void EnterMutex ()
{
::WaitForSingleObject ( hMutex, INFINITE ) ;
}
Now you own it, and when you're done with it you must call ReleaseMutex
void LeaveMutex ()
{
::ReleaseMutex ( hMutex ) ;
}
I think your problem is probably a confusion over ownership. The two functions above are naturally wrapped up into the constructor/destructor of a class, and error returns handled by throwing exceptions, but that's another discussion really.
Paul
|
|
|
|
|
What you say makes sence, but in my situation if I call EnterMutex() then I have a long wait!!
I have checked that the DLL has released the mutex, so it should be 'unowned'.
Still confused!?!
Graham.
grahamfff
|
|
|
|
|
So you must have some sort of deadlock, the question is where, and I don't think we can help you here without all the code.
I think that a single thread can 'Wait' for a Mutex multiple times and the wait will always complete immediately. But each wait must be accompanied with a matching ReleaseMutex. Perhaps there's something like that but with insufficient releases happening in your code flow?
Paul
|
|
|
|
|
You only check the WAIT_OBJECT_0 returned from WaitForSingleObject(). Check for other possible return values.
Post the code that creates the mutex in the EXE.
Kuphryn
|
|
|
|
|
I noticed that whenever I use the "<<" bitwise left shift operator. The result value is incorrect. The bitwise right shift is correct. Whats up with this? Any ideas? ie 49<<3 should be 136, but I get 392.
Thanks
|
|
|
|
|
|
I assume he is taking it as 8bits and therefore the top bit falls off the end!
Ant.
|
|
|
|
|
Then you should be shifting an 8bit variable, like 'unsigned char'. You are probably shifting 'int' or something. Or cut it to 8 bits with AND 255
|
|
|
|
|
I see what you have done. You need to AND with 255 to get the answer.
Ant.
|
|
|
|
|
one time right shift is like divide with 2 and one time left shift is like multiple wiht 2. So How can you find 136 result
|
|
|
|
|
I am running my application in Visual Studio .NET & am getting the following error "It is illegal to call out while inside message filter"
What can be causing this error to occur?
Thanks
|
|
|
|
|
Hi,
From my experience - this is caused by COM re-entrancy.
For example, COM server has called back into your app (via eventing) and you are then calling back into the COM server.
COM's telling you its blocking the call because it hasn't finished processing the previous method call.
I did the following which still blocks but without the annoying message
class CBusyState
{
public:
CBusyState(BOOL bEnterBusyState = TRUE,
SERVERCALL scBusyReply = SERVERCALL_RETRYLATER)
: m_bBusy(FALSE)
{
m_pMessageFilter = AfxOleGetMessageFilter();
if (bEnterBusyState)
Begin(scBusyReply);
}
~COasisBusyState()
{
End();
};
BOOL Begin(SERVERCALL scBusyReply = SERVERCALL_RETRYLATER)
{
if (m_pMessageFilter && !m_bBusy)
{
m_pMessageFilter->SetBusyReply(scBusyReply);
m_pMessageFilter->BeginBusyState();
m_bBusy = TRUE;
}
return m_bBusy;
}
void End()
{
if (m_pMessageFilter && m_bBusy)
{
m_pMessageFilter->EndBusyState();
m_bBusy = FALSE;
}
}
private:
BOOL m_bBusy;
COleMessageFilter* m_pMessageFilter;
};
Then whenever we call the COM server, I'd put the object on the stack, e.g.
function xyzxyzxyz()
{
CBusyState blocker(TRUE);
MyCOMServer->method(xyz)
}
Hope this helps,
Andy
|
|
|
|
|
Thanks alot for your response, I will try your idea, for now I put some workaround in my code.
Thanks again for the info.
|
|
|
|
|
I am getting server errors when trying to download a CAB file from a webserver.
I think the problem is that the default headers don't allow for CAB file mime type.
What string do I need to use in my call to
CHttpFile.AddRequestheaders(); to get this file?
I believe this is the problem, because if I change the URL to point to an HTML page, but leave everything else the same, then the file downloads just fine.
Thanks!
(I am also posting this in the Web Develpment forum)
//placeholder for witty verbiage
|
|
|
|
|
does "GET /.../.../foo.cab" really not work?
Don't try it, just do it!
|
|
|
|
|
|
I have set a MSChart control in my dialog,a error happened.
m_Chart.SetColumn(i);
when i=5,compiler shows :index given is out of bound and i=4,all right. Why?
|
|
|
|
|
I think the default column count in the control is 4.You can set the number of columns from the properties of the control.
|
|
|
|
|
thanks a lot,I have resulved this problem.
|
|
|
|
|
How can i calculate the idle time of machine in VC++.
|
|
|
|
|
Does GetLastInputInfo() help?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|