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. Event objects VS Global variables

Event objects VS Global variables

Scheduled Pinned Locked Moved C / C++ / MFC
7 Posts 5 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.
  • S Offline
    S Offline
    sourabhmehta
    wrote on last edited by
    #1

    Hi Everyone, I am new to multithreading. I was trying controlling threads using EVENT Objects. FYI i have single process and multiple threads. I could achieve the same results without using events. Instead i used global flags to achieve the same.I can totally understand that using global variable is not a good practice. Can anybody tell, what else is a major difference and if anybody can give some specific examples where only events can be used. Thanks in advance

    Richard Andrew x64R S F 3 Replies Last reply
    0
    • S sourabhmehta

      Hi Everyone, I am new to multithreading. I was trying controlling threads using EVENT Objects. FYI i have single process and multiple threads. I could achieve the same results without using events. Instead i used global flags to achieve the same.I can totally understand that using global variable is not a good practice. Can anybody tell, what else is a major difference and if anybody can give some specific examples where only events can be used. Thanks in advance

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      The main difference is that a thread can wait on an event but not a global variable.

      The difficult we do right away... ...the impossible takes slightly longer.

      1 Reply Last reply
      0
      • S sourabhmehta

        Hi Everyone, I am new to multithreading. I was trying controlling threads using EVENT Objects. FYI i have single process and multiple threads. I could achieve the same results without using events. Instead i used global flags to achieve the same.I can totally understand that using global variable is not a good practice. Can anybody tell, what else is a major difference and if anybody can give some specific examples where only events can be used. Thanks in advance

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        When a thread waits on an event it isn't scheduled and so consumes so no CPU time. Waiting on a global variable requires polling and so does.

        Steve

        D 1 Reply Last reply
        0
        • S Stephen Hewitt

          When a thread waits on an event it isn't scheduled and so consumes so no CPU time. Waiting on a global variable requires polling and so does.

          Steve

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

          Stephen Hewitt wrote:

          ...and so consumes so CPU time. Waiting on a global variable requires polling and so does.

          Am I misreading this?

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          Richard Andrew x64R S 2 Replies Last reply
          0
          • D David Crow

            Stephen Hewitt wrote:

            ...and so consumes so CPU time. Waiting on a global variable requires polling and so does.

            Am I misreading this?

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            Richard Andrew x64R Offline
            Richard Andrew x64R Offline
            Richard Andrew x64
            wrote on last edited by
            #5

            He meant "NO cpu time."

            The difficult we do right away... ...the impossible takes slightly longer.

            1 Reply Last reply
            0
            • D David Crow

              Stephen Hewitt wrote:

              ...and so consumes so CPU time. Waiting on a global variable requires polling and so does.

              Am I misreading this?

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              You are reading correctly, I just spelt "no" wrong. And it's an easy word too.

              Steve

              1 Reply Last reply
              0
              • S sourabhmehta

                Hi Everyone, I am new to multithreading. I was trying controlling threads using EVENT Objects. FYI i have single process and multiple threads. I could achieve the same results without using events. Instead i used global flags to achieve the same.I can totally understand that using global variable is not a good practice. Can anybody tell, what else is a major difference and if anybody can give some specific examples where only events can be used. Thanks in advance

                F Offline
                F Offline
                Frankie C
                wrote on last edited by
                #7

                Don't post questions on many places. You already posted it here[^].

                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