troubleshooting Question

CSingleLock problem

Avatar of l_madhavi
l_madhavi asked on
System Programming
1 Comment1 Solution558 ViewsLast Modified:
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<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);
      ASSERT(!m_bAcquired);

      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?

Thanks
Madhavi.


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