LOCK CMutex, CSingleLock, CMultiLock, ?????
Posted on 2004-10-22
I have a multithreaded application, and I'm trying to set it up so that only one thread can pass through a paticular function at one time.
void FileWatcher::AddFileName(const CString& NewFile)
m_lockingobj.Lock(); //If already lock, then waith until unlock
So what I bascially want is when the Lock member function is called, if another thread has it locked already, then the current thread should be on hold until the other thread unlocks it.
When I run the above code, I get an ASSERT error at runtime in the following MFC CSingleLock member function:
BOOL CSingleLock::Lock(DWORD dwTimeOut /* = INFINITE */)
ASSERT(m_pObject != NULL || m_hObject != NULL);
ASSERT(!m_bAcquired); // <--- <--- *** Error here ***
m_bAcquired = m_pObject->Lock(dwTimeOut);
Is CSingleLock the right class for the functionallity I'm looking for, should I be using something else.
This is pretty simple to do in UNIX with POSIX functions, but I can't seem to figure out the correct method using MFC.