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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CCriticalSection problem. Pls help!

CCriticalSection problem. Pls help!

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 3 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.
  • A Offline
    A Offline
    a_du
    wrote on last edited by
    #1

    I have a dialog which contains a CListCtrl to dislplay some information. two cwinthreads from other dlg keep updating the data of the CListCtrl. the CListCtrl's handle is passed to the threads and there is a Shared CriticalSection among these 3 objects. when i close the dlg, i want to set a flg to inform the two threads that the list is destroyed. so i call in the exit event of the dlg: lock.Lock(); destroyFlg = true; // the threads will check this flg before access the list //and access to the list is protected by lock & unlock lock.UnLock(); what happend is that , the dlg is hung. i traced and find it hung at lock.Lock(); there is only one crictical section and i am sure i have paired each lock() with a unlock(). why this still happend? Some one knows please help me. thanx a lot. :(

    D A 2 Replies Last reply
    0
    • A a_du

      I have a dialog which contains a CListCtrl to dislplay some information. two cwinthreads from other dlg keep updating the data of the CListCtrl. the CListCtrl's handle is passed to the threads and there is a Shared CriticalSection among these 3 objects. when i close the dlg, i want to set a flg to inform the two threads that the list is destroyed. so i call in the exit event of the dlg: lock.Lock(); destroyFlg = true; // the threads will check this flg before access the list //and access to the list is protected by lock & unlock lock.UnLock(); what happend is that , the dlg is hung. i traced and find it hung at lock.Lock(); there is only one crictical section and i am sure i have paired each lock() with a unlock(). why this still happend? Some one knows please help me. thanx a lot. :(

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      a_du wrote: two cwinthreads from other dlg keep updating the data of the CListCtrl. You can avoid a whole lot of problems by simply having these other two threads post a message back to the main thread (the one that actually owns the GUI). Locking and synchronizing are a headache if not done 100% correctly.


      "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

      1 Reply Last reply
      0
      • A a_du

        I have a dialog which contains a CListCtrl to dislplay some information. two cwinthreads from other dlg keep updating the data of the CListCtrl. the CListCtrl's handle is passed to the threads and there is a Shared CriticalSection among these 3 objects. when i close the dlg, i want to set a flg to inform the two threads that the list is destroyed. so i call in the exit event of the dlg: lock.Lock(); destroyFlg = true; // the threads will check this flg before access the list //and access to the list is protected by lock & unlock lock.UnLock(); what happend is that , the dlg is hung. i traced and find it hung at lock.Lock(); there is only one crictical section and i am sure i have paired each lock() with a unlock(). why this still happend? Some one knows please help me. thanx a lot. :(

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        Consider using a wrapper class to lock your object. See following code: http://code.axter.com/sync\_ptr.h The above wrapper class will automatically lock and unlock your object, so you don't have to worry about forgetting.

        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