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. MFC: CCriticalSection problem

MFC: CCriticalSection problem

Scheduled Pinned Locked Moved C / C++ / MFC
c++debugginghelpquestion
5 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.
  • P Offline
    P Offline
    Pixinger77
    wrote on last edited by
    #1

    I create a new project (MFC Dialog) and place a button on the dialog. The code that the button performs is the following: CCriticalSection c; c.Lock(); c.Lock(); c.Unlock(); c.Unlock(); When I start the Program in DEBUG-Mode I expect the following behaviour: 1. The CritSec is created. 2. The first Lock is applied. 3. The second call to Lock should result in a deadlock. :omg: But that is not the case. The code will run without any problems. WHY:confused:!!!! Is there some different behaviour in DEBUG-Mode, or what? Greets Snow

    S 1 Reply Last reply
    0
    • P Pixinger77

      I create a new project (MFC Dialog) and place a button on the dialog. The code that the button performs is the following: CCriticalSection c; c.Lock(); c.Lock(); c.Unlock(); c.Unlock(); When I start the Program in DEBUG-Mode I expect the following behaviour: 1. The CritSec is created. 2. The first Lock is applied. 3. The second call to Lock should result in a deadlock. :omg: But that is not the case. The code will run without any problems. WHY:confused:!!!! Is there some different behaviour in DEBUG-Mode, or what? Greets Snow

      S Offline
      S Offline
      sunit5
      wrote on last edited by
      #2

      what is the return value when second lock is applied -- modified at 6:51 Monday 28th November, 2005

      P 1 Reply Last reply
      0
      • S sunit5

        what is the return value when second lock is applied -- modified at 6:51 Monday 28th November, 2005

        P Offline
        P Offline
        Pixinger77
        wrote on last edited by
        #3

        both are true

        B 1 Reply Last reply
        0
        • P Pixinger77

          both are true

          B Offline
          B Offline
          BadKarma
          wrote on last edited by
          #4

          Hi, the CCriticalSection object encapsulates the CRITICAL_SECTION type. The lock function calls the EnterCriticalSection API. So from the MSDN libs I found this:

          After a thread has ownership of a critical section, it can make additional calls to
          EnterCriticalSection or TryEnterCriticalSection without blocking its execution. This prevents a
          thread from deadlocking itself while waiting for a critical section that it already owns. The
          thread enters the critical section each time EnterCriticalSection and TryEnterCriticalSection
          succeed. A thread must call LeaveCriticalSection once for each time that it entered the critical
          section.

          So it is normal behaviour codito ergo sum -- modified at 11:29 Monday 28th November, 2005

          P 1 Reply Last reply
          0
          • B BadKarma

            Hi, the CCriticalSection object encapsulates the CRITICAL_SECTION type. The lock function calls the EnterCriticalSection API. So from the MSDN libs I found this:

            After a thread has ownership of a critical section, it can make additional calls to
            EnterCriticalSection or TryEnterCriticalSection without blocking its execution. This prevents a
            thread from deadlocking itself while waiting for a critical section that it already owns. The
            thread enters the critical section each time EnterCriticalSection and TryEnterCriticalSection
            succeed. A thread must call LeaveCriticalSection once for each time that it entered the critical
            section.

            So it is normal behaviour codito ergo sum -- modified at 11:29 Monday 28th November, 2005

            P Offline
            P Offline
            Pixinger77
            wrote on last edited by
            #5

            Thanks a lot!

            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