Can someone tell me if I have got this schem correct for usin Mutexs for controlling access to shared data (memory mapped) between two programs.
Each program creates the Mutex as follows:-
m_hMutex = ::CreateMutex(NULL,FALSE,"CSLSharedMemLock");
Each program uses the following procedure before read/write operations:-
bool WaitForMutex(void)
{
/* This procedure will wait for a Mutex before allowing any
write access to the shared area. */
if(m_hMutex)
{
if
:WaitForSingleObject(m_hMutex,INFINITE) == WAIT_OBJECT_0)
{
return true;
}
return false;
}
then we read data or write data and release the handle.
ReleaseMutex(m_hMutex);
and then
CloseHandle (m_hMutex);
But one of the programs is a DLL and that does not call
CloseHandle (m_hMutex);
The 2 programs (EXE and DLL) work OK without using the Mutex, but lock up as soon as I start to use a Mutex; i.e. never return from WaitForMutex.
I want to protect the shared data, any comments?
Sweep123.
Each program creates the Mutex as follows:-
m_hMutex = ::CreateMutex(NULL,FALSE,"CSLSharedMemLock");
Each program uses the following procedure before read/write operations:-
bool WaitForMutex(void)
{
/* This procedure will wait for a Mutex before allowing any
write access to the shared area. */
if(m_hMutex)
{
if
{
return true;
}
return false;
}
then we read data or write data and release the handle.
ReleaseMutex(m_hMutex);
and then
CloseHandle (m_hMutex);
But one of the programs is a DLL and that does not call
CloseHandle (m_hMutex);
The 2 programs (EXE and DLL) work OK without using the Mutex, but lock up as soon as I start to use a Mutex; i.e. never return from WaitForMutex.
I want to protect the shared data, any comments?
Sweep123.