Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CSingleLock problem

CSingleLock problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpdebuggingperformance
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    ledallam
    wrote on last edited by
    #1

    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);

    J 2 Replies Last reply
    0
    • L ledallam

      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);

      J Offline
      J Offline
      James R Twine
      wrote on last edited by
      #2

      [Deleted - posted incorrectly - see next post]

      1 Reply Last reply
      0
      • L ledallam

        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);

        J Offline
        J Offline
        James R Twine
        wrote on last edited by
        #3

        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!)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups