CSingleLock problem
-
Hi, I am working with threads. I have a thread safe class as shown below. class CUxx_MS_ListWordToPtr { // VARIABLE DECLARATION SECTION public: private: //##ModelId=38BB19E501C9 CUxx_MS_CriticalSection m_Lockable; //##ModelId=38BB19E501B5 CMapWordToPtr* m_List; CSemaphore threadlock; // FUNCTION DECLARATION SECTION public: // Construction //##ModelId=38BB19E50291 CUxx_MS_ListWordToPtr(int nBlockSize = 10) { m_List = new CMapWordToPtr(nBlockSize); } // lock functions //##ModelId=38BB19E50290 void Lock() { m_Lockable.Lock(); } //##ModelId=38BB19E50287 void Unlock() { m_Lockable.Unlock(); } // Attributes // number of elements //##ModelId=38BB19E50286 int GetCount() const { //CUxx_MS_Lock localLock((class CUxx_MS_LockableObject *) &m_Lockable); // CUxx_MS_CriticalSection cs; CSingleLock singleLock( (CSyncObject*)&threadlock); singleLock.Lock(); int count = m_List->GetCount();; singleLock.Unlock(); return count; } //##ModelId=38BB19E5027D int GetCountNoLock() const { return m_List->GetCount(); } //##ModelId=38BB19E5027C BOOL IsEmpty() const { //CUxx_MS_Lock localLock((class CUxx_MS_LockableObject *) &m_Lockable); CSingleLock singleLock( (CSyncObject*)&threadlock); singleLock.Lock(); BOOL flag = m_List->IsEmpty(); singleLock.Unlock(); return flag; } //##ModelId=38BB19E50274 BOOL IsEmptyNoLock() const { return m_List->IsEmpty(); } ........ } The way I use this class is CTypedPtrMap ListOutput; when I call methods like, CString* pCStr; CMemMapMgr* pCommunicationObject; ListOutput.Lookup(*pCStr, pCommObject), sometimes it shows an error message-> The instruction at ".." referenced memory at " ", The memory could not be read and when I debug the code, it shows the root as BOOL CSingleLock::Lock(DWORD dwTimeOut /* = INFINITE */) { ASSERT(m_pObject != NULL || m_hObject != NULL); ASSERT(!m_bAcquired);
-
Hi, I am working with threads. I have a thread safe class as shown below. class CUxx_MS_ListWordToPtr { // VARIABLE DECLARATION SECTION public: private: //##ModelId=38BB19E501C9 CUxx_MS_CriticalSection m_Lockable; //##ModelId=38BB19E501B5 CMapWordToPtr* m_List; CSemaphore threadlock; // FUNCTION DECLARATION SECTION public: // Construction //##ModelId=38BB19E50291 CUxx_MS_ListWordToPtr(int nBlockSize = 10) { m_List = new CMapWordToPtr(nBlockSize); } // lock functions //##ModelId=38BB19E50290 void Lock() { m_Lockable.Lock(); } //##ModelId=38BB19E50287 void Unlock() { m_Lockable.Unlock(); } // Attributes // number of elements //##ModelId=38BB19E50286 int GetCount() const { //CUxx_MS_Lock localLock((class CUxx_MS_LockableObject *) &m_Lockable); // CUxx_MS_CriticalSection cs; CSingleLock singleLock( (CSyncObject*)&threadlock); singleLock.Lock(); int count = m_List->GetCount();; singleLock.Unlock(); return count; } //##ModelId=38BB19E5027D int GetCountNoLock() const { return m_List->GetCount(); } //##ModelId=38BB19E5027C BOOL IsEmpty() const { //CUxx_MS_Lock localLock((class CUxx_MS_LockableObject *) &m_Lockable); CSingleLock singleLock( (CSyncObject*)&threadlock); singleLock.Lock(); BOOL flag = m_List->IsEmpty(); singleLock.Unlock(); return flag; } //##ModelId=38BB19E50274 BOOL IsEmptyNoLock() const { return m_List->IsEmpty(); } ........ } The way I use this class is CTypedPtrMap ListOutput; when I call methods like, CString* pCStr; CMemMapMgr* pCommunicationObject; ListOutput.Lookup(*pCStr, pCommObject), sometimes it shows an error message-> The instruction at ".." referenced memory at " ", The memory could not be read and when I debug the code, it shows the root as BOOL CSingleLock::Lock(DWORD dwTimeOut /* = INFINITE */) { ASSERT(m_pObject != NULL || m_hObject != NULL); ASSERT(!m_bAcquired);
[Deleted - posted incorrectly - see next post]
-
Hi, I am working with threads. I have a thread safe class as shown below. class CUxx_MS_ListWordToPtr { // VARIABLE DECLARATION SECTION public: private: //##ModelId=38BB19E501C9 CUxx_MS_CriticalSection m_Lockable; //##ModelId=38BB19E501B5 CMapWordToPtr* m_List; CSemaphore threadlock; // FUNCTION DECLARATION SECTION public: // Construction //##ModelId=38BB19E50291 CUxx_MS_ListWordToPtr(int nBlockSize = 10) { m_List = new CMapWordToPtr(nBlockSize); } // lock functions //##ModelId=38BB19E50290 void Lock() { m_Lockable.Lock(); } //##ModelId=38BB19E50287 void Unlock() { m_Lockable.Unlock(); } // Attributes // number of elements //##ModelId=38BB19E50286 int GetCount() const { //CUxx_MS_Lock localLock((class CUxx_MS_LockableObject *) &m_Lockable); // CUxx_MS_CriticalSection cs; CSingleLock singleLock( (CSyncObject*)&threadlock); singleLock.Lock(); int count = m_List->GetCount();; singleLock.Unlock(); return count; } //##ModelId=38BB19E5027D int GetCountNoLock() const { return m_List->GetCount(); } //##ModelId=38BB19E5027C BOOL IsEmpty() const { //CUxx_MS_Lock localLock((class CUxx_MS_LockableObject *) &m_Lockable); CSingleLock singleLock( (CSyncObject*)&threadlock); singleLock.Lock(); BOOL flag = m_List->IsEmpty(); singleLock.Unlock(); return flag; } //##ModelId=38BB19E50274 BOOL IsEmptyNoLock() const { return m_List->IsEmpty(); } ........ } The way I use this class is CTypedPtrMap ListOutput; when I call methods like, CString* pCStr; CMemMapMgr* pCommunicationObject; ListOutput.Lookup(*pCStr, pCommObject), sometimes it shows an error message-> The instruction at ".." referenced memory at " ", The memory could not be read and when I debug the code, it shows the root as BOOL CSingleLock::Lock(DWORD dwTimeOut /* = INFINITE */) { ASSERT(m_pObject != NULL || m_hObject != NULL); ASSERT(!m_bAcquired);
You really need to format your code using the PRE tags...! Anyway, in this code:
CString* pCStr;
CMemMapMgr* pCommunicationObject;
ListOutput.Lookup(*pCStr, pCommObject);You are using two uninitialized pointers there, and dereferencing the first one, which is likely the cause of your crash. Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!)