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. about event

about event

Scheduled Pinned Locked Moved C / C++ / MFC
question
8 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.
  • H Offline
    H Offline
    HOW WHAT
    wrote on last edited by
    #1

    while (!bEnd) { Sleep(0); } and HANDLE hEventEnd = CreateEvent(...); WaitForSingleObject(hEventEnd...); ---------------------------------------------- which better?

    C 1 Reply Last reply
    0
    • H HOW WHAT

      while (!bEnd) { Sleep(0); } and HANDLE hEventEnd = CreateEvent(...); WaitForSingleObject(hEventEnd...); ---------------------------------------------- which better?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      HOW WHAT wrote:

      hile (!bEnd) { Sleep(0); }

      is obviously a disaster.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      H 1 Reply Last reply
      0
      • C Christian Graus

        HOW WHAT wrote:

        hile (!bEnd) { Sleep(0); }

        is obviously a disaster.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        H Offline
        H Offline
        HOW WHAT
        wrote on last edited by
        #3

        emm, why?

        C J 2 Replies Last reply
        0
        • H HOW WHAT

          emm, why?

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Sleep(0) plainly does nothing, and so you're going to start another thread, but at the same time, have your main thread check a bool over and over again, as fast as it can ? The mechanisms like WaitForSingleEvent exist precisely to stop people doing stuff like a hard loop to check a bool.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          H 1 Reply Last reply
          0
          • H HOW WHAT

            emm, why?

            J Offline
            J Offline
            Joan M
            wrote on last edited by
            #5

            CPU resources... a while the is always looping takes al the computer resources in order to be done as fast as possible, in the other way is like a callback, the OS handles it...

            https://www.robotecnik.com freelance robots, PLC and CNC programmer.

            H 1 Reply Last reply
            0
            • C Christian Graus

              Sleep(0) plainly does nothing, and so you're going to start another thread, but at the same time, have your main thread check a bool over and over again, as fast as it can ? The mechanisms like WaitForSingleEvent exist precisely to stop people doing stuff like a hard loop to check a bool.

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

              H Offline
              H Offline
              HOW WHAT
              wrote on last edited by
              #6

              e...But i see WaitForSingleObject sources also use do {}while(...), Sleep and WaitForSingleObject sources as much as same....

              1 Reply Last reply
              0
              • J Joan M

                CPU resources... a while the is always looping takes al the computer resources in order to be done as fast as possible, in the other way is like a callback, the OS handles it...

                H Offline
                H Offline
                HOW WHAT
                wrote on last edited by
                #7

                Which you think better?

                J 1 Reply Last reply
                0
                • H HOW WHAT

                  Which you think better?

                  J Offline
                  J Offline
                  Joan M
                  wrote on last edited by
                  #8

                  I've given my five to Mr. Graus... :rolleyes:

                  https://www.robotecnik.com freelance robots, PLC and CNC programmer.

                  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