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. Need a worker thread wait timer..

Need a worker thread wait timer..

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 4 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
    aquawicket
    wrote on last edited by
    #1

    I have a worker thread that needs to wait a certain amount of miliseconds before resuming.. I would just got the for(i=0; i<10000000000; i++) route, but i'm afaid it will eat up the CPU. I'm trying to stay out of a loop but stay in the worker thread. I need my main thread to be very alert and time accurate while this worker thread is waiting. I've looked at all the timer functions.. can't seem to find the one to do the trick.. any ideas.. ? Workthread() { //do some processing //wait //do more processing //return }

    L M 2 Replies Last reply
    0
    • A aquawicket

      I have a worker thread that needs to wait a certain amount of miliseconds before resuming.. I would just got the for(i=0; i<10000000000; i++) route, but i'm afaid it will eat up the CPU. I'm trying to stay out of a loop but stay in the worker thread. I need my main thread to be very alert and time accurate while this worker thread is waiting. I've looked at all the timer functions.. can't seem to find the one to do the trick.. any ideas.. ? Workthread() { //do some processing //wait //do more processing //return }

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Sleep[^] :rolleyes: Although why someone is writing multi-threaded code prior to learning the threading API's is... well .... pretty crazy.

      led mike

      1 Reply Last reply
      0
      • A aquawicket

        I have a worker thread that needs to wait a certain amount of miliseconds before resuming.. I would just got the for(i=0; i<10000000000; i++) route, but i'm afaid it will eat up the CPU. I'm trying to stay out of a loop but stay in the worker thread. I need my main thread to be very alert and time accurate while this worker thread is waiting. I've looked at all the timer functions.. can't seem to find the one to do the trick.. any ideas.. ? Workthread() { //do some processing //wait //do more processing //return }

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        On Windows, try Sleep(milliseconds) Eats NO CPU :)

        L 1 Reply Last reply
        0
        • M Mark Salsbery

          On Windows, try Sleep(milliseconds) Eats NO CPU :)

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          HA! Beat you by the click of an eye. ;P

          led mike

          M 1 Reply Last reply
          0
          • L led mike

            HA! Beat you by the click of an eye. ;P

            led mike

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            ;P

            A 1 Reply Last reply
            0
            • M Mark Salsbery

              ;P

              A Offline
              A Offline
              aquawicket
              wrote on last edited by
              #6

              duh... didn't have the time.h header in... my bad.. thanks guys

              T 1 Reply Last reply
              0
              • A aquawicket

                duh... didn't have the time.h header in... my bad.. thanks guys

                T Offline
                T Offline
                ThatsAlok
                wrote on last edited by
                #7

                aquawicket wrote:

                duh... didn't have the time.h header in... my bad.. thanks guys

                try more efficient WaitForSingleObject with retrun value WAIT_TIMEOUT

                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief And You

                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