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. Hard question about Critical section - in C++ ....

Hard question about Critical section - in C++ ....

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++
8 Posts 6 Posters 1 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
    Lost User
    wrote on last edited by
    #1

    Hello, When you define in some function a critical section you define a critical section block or variable ? :confused::confused::confused: I will explain - when some thread get to this Critical section and the Critical section is lock - so this thread will go sleep until this Critical section will be unlock and the event will be called to rise up. But my problem (or my bad understanding) is about the block of the critical section - i think that the critical section is only to block thread and make the thread sleep and have no direct connection to the block - but some other thought is that the critical section is define only on block. Can someone explain the main idea of the critical section in this case ? Thanks on any help. :-O

    E D J A 4 Replies Last reply
    0
    • L Lost User

      Hello, When you define in some function a critical section you define a critical section block or variable ? :confused::confused::confused: I will explain - when some thread get to this Critical section and the Critical section is lock - so this thread will go sleep until this Critical section will be unlock and the event will be called to rise up. But my problem (or my bad understanding) is about the block of the critical section - i think that the critical section is only to block thread and make the thread sleep and have no direct connection to the block - but some other thought is that the critical section is define only on block. Can someone explain the main idea of the critical section in this case ? Thanks on any help. :-O

      E Offline
      E Offline
      Eric Dahlvang
      wrote on last edited by
      #2

      There are numerous good articles about this: Check Here.[^] ---------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

      1 Reply Last reply
      0
      • L Lost User

        Hello, When you define in some function a critical section you define a critical section block or variable ? :confused::confused::confused: I will explain - when some thread get to this Critical section and the Critical section is lock - so this thread will go sleep until this Critical section will be unlock and the event will be called to rise up. But my problem (or my bad understanding) is about the block of the critical section - i think that the critical section is only to block thread and make the thread sleep and have no direct connection to the block - but some other thought is that the critical section is define only on block. Can someone explain the main idea of the critical section in this case ? Thanks on any help. :-O

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

        yanshof wrote:

        Can someone explain the main idea of the critical section in this case ?

        See here.


        "The largest fire starts but with the smallest spark." - David Crow

        "Judge not by the eye but by the heart." - Native American Proverb

        L 1 Reply Last reply
        0
        • D David Crow

          yanshof wrote:

          Can someone explain the main idea of the critical section in this case ?

          See here.


          "The largest fire starts but with the smallest spark." - David Crow

          "Judge not by the eye but by the heart." - Native American Proverb

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I read those both and i still have the same question. My question will not appear in there.... like i said this is hard question...

          D 1 Reply Last reply
          0
          • L Lost User

            Hello, When you define in some function a critical section you define a critical section block or variable ? :confused::confused::confused: I will explain - when some thread get to this Critical section and the Critical section is lock - so this thread will go sleep until this Critical section will be unlock and the event will be called to rise up. But my problem (or my bad understanding) is about the block of the critical section - i think that the critical section is only to block thread and make the thread sleep and have no direct connection to the block - but some other thought is that the critical section is define only on block. Can someone explain the main idea of the critical section in this case ? Thanks on any help. :-O

            J Offline
            J Offline
            Jorgen Sigvardsson
            wrote on last edited by
            #5

            yanshof wrote:

            - i think that the critical section is only to block thread and make the thread sleep and have no direct connection to the block - but some other thought is that the critical section is define only on block.

            I'm not sure I follow.. A CRITICAL_SECTION variable is an opaque object which holds a lock state. It's not a handle to anything, like mutexes are (they are kernel objects). I'm not sure what you mean by block, but I'm going to assume it's a body of code such as { ... }. A critical section is not automatically associated with such a block. The state of the critical section object is determined by the Enter/Leave functions, and can span over any number of blocks.

            -- 100% natural. No superstitious additives.

            1 Reply Last reply
            0
            • L Lost User

              Hello, When you define in some function a critical section you define a critical section block or variable ? :confused::confused::confused: I will explain - when some thread get to this Critical section and the Critical section is lock - so this thread will go sleep until this Critical section will be unlock and the event will be called to rise up. But my problem (or my bad understanding) is about the block of the critical section - i think that the critical section is only to block thread and make the thread sleep and have no direct connection to the block - but some other thought is that the critical section is define only on block. Can someone explain the main idea of the critical section in this case ? Thanks on any help. :-O

              A Offline
              A Offline
              Arvind Bharti
              wrote on last edited by
              #6

              A critical section is a small section of code that requires exclusive access to some shared resource before the code can execute. To protect that section of code we need to encapsulate that code in EnterCriticalSection and LeaveCriticalSection function call. Better avoid using 'block' terminology.

              R 1 Reply Last reply
              0
              • A Arvind Bharti

                A critical section is a small section of code that requires exclusive access to some shared resource before the code can execute. To protect that section of code we need to encapsulate that code in EnterCriticalSection and LeaveCriticalSection function call. Better avoid using 'block' terminology.

                R Offline
                R Offline
                Rick York
                wrote on last edited by
                #7

                In MFC-speak that would be a CCriticalSection object along with a CSingleLock object.

                1 Reply Last reply
                0
                • L Lost User

                  I read those both and i still have the same question. My question will not appear in there.... like i said this is hard question...

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

                  yanshof wrote:

                  I read those both and i still have the same question.

                  Why? What part did you not understand?

                  yanshof wrote:

                  My question will not appear in there....

                  Maybe not directly, but you can easily infer the answer.

                  yanshof wrote:

                  When you define in some function a critical section you define a critical section block or variable ?

                  A critical section is a block of code (that can contain variables).

                  yanshof wrote:

                  Can someone explain the main idea of the critical section in this case ?

                  The link I provided you explained this in detail.


                  "The largest fire starts but with the smallest spark." - David Crow

                  "Judge not by the eye but by the heart." - Native American Proverb

                  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