troubleshooting Question

CSingleLock problem

Avatar of l_madhavi
l_madhavi asked on
System Programming
1 Comment1 Solution558 ViewsLast Modified:

I am working with threads. I have a thread safe class as shown below.
class CUxx_MS_ListWordToPtr

      CUxx_MS_CriticalSection      m_Lockable;
      CMapWordToPtr* m_List;
 CSemaphore threadlock;



// Construction
      CUxx_MS_ListWordToPtr(int nBlockSize = 10)

                  m_List = new CMapWordToPtr(nBlockSize);

// lock functions
      void Lock()
      void Unlock()

// Attributes
      // number of elements
      int GetCount() const
                  //CUxx_MS_Lock      localLock((class CUxx_MS_LockableObject *) &m_Lockable);
            //      CUxx_MS_CriticalSection cs;
                  CSingleLock singleLock( (CSyncObject*)&threadlock);
                  int count = m_List->GetCount();;
                  return count;
      int GetCountNoLock() const
                  return m_List->GetCount();
      BOOL IsEmpty() const
                  //CUxx_MS_Lock      localLock((class CUxx_MS_LockableObject *) &m_Lockable);
                   CSingleLock singleLock( (CSyncObject*)&threadlock);
                  BOOL flag = m_List->IsEmpty();
                  return flag;
      BOOL IsEmptyNoLock() const
                  return m_List->IsEmpty();



The way  I use this class is
CTypedPtrMap<CUxx_MS_ListPtrToPtr, CMemMapMgr*, CString*>       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);

      m_bAcquired = m_pObject->Lock(dwTimeOut);
      return m_bAcquired;

Can anyone please help me to understand the reason for this crash and how to resolve this one?


Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros