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. What the best way to sleep 1 ms

What the best way to sleep 1 ms

Scheduled Pinned Locked Moved C / C++ / MFC
linuxhardwarequestion
12 Posts 8 Posters 3 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 leatrop

    I tried Sleep(1) but it looks like win xp and win 2000 wait for 10 ms instead. I could be wrong but if I do Sleep(10) then delay between characters I am sending exactly as with Sleep(1). I am not a Windows programmer, I am specialising in embedded real-time and particular in Unix systems and I know that often default kernel time resolution is 10 ms (eg. linux). What resolution windows Xp, 2000, 95, 98 have? Are they the same? What the best way to sleep for 1 ms? Thank you

    A Offline
    A Offline
    Adi Narayana Vemuru
    wrote on last edited by
    #2

    Hello, write your own delay routine using high-resolution APIs, QueeryPerformaceCounter() and QueeryPerformaceFrequency(. you can achieve timer even in microseconds. hope the above helps. regards, Adi

    1 Reply Last reply
    0
    • L leatrop

      I tried Sleep(1) but it looks like win xp and win 2000 wait for 10 ms instead. I could be wrong but if I do Sleep(10) then delay between characters I am sending exactly as with Sleep(1). I am not a Windows programmer, I am specialising in embedded real-time and particular in Unix systems and I know that often default kernel time resolution is 10 ms (eg. linux). What resolution windows Xp, 2000, 95, 98 have? Are they the same? What the best way to sleep for 1 ms? Thank you

      N Offline
      N Offline
      namaskaaram
      wrote on last edited by
      #3

      :~ getting a precise value in the microsecond range in windows is practically not possible ,taking into account that it handles many task at a time,since windows aint an real time os.....aint it????? "faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13

      A T 2 Replies Last reply
      0
      • L leatrop

        I tried Sleep(1) but it looks like win xp and win 2000 wait for 10 ms instead. I could be wrong but if I do Sleep(10) then delay between characters I am sending exactly as with Sleep(1). I am not a Windows programmer, I am specialising in embedded real-time and particular in Unix systems and I know that often default kernel time resolution is 10 ms (eg. linux). What resolution windows Xp, 2000, 95, 98 have? Are they the same? What the best way to sleep for 1 ms? Thank you

        J Offline
        J Offline
        James R Twine
        wrote on last edited by
        #4

        The best way is to run under a real-time OS...! :)    Seriously, I think that the solution given to use the QueryPerformance*(...) functions (also check out the multimedia timers) in a tight loop would do it for you.  You might have to worry about the cases where your qauntum expires during the execution of the loop, though.    Peace! -=- James


        If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
        Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
        DeleteFXPFiles & CheckFavorites (Please rate this post!)

        T 1 Reply Last reply
        0
        • J James R Twine

          The best way is to run under a real-time OS...! :)    Seriously, I think that the solution given to use the QueryPerformance*(...) functions (also check out the multimedia timers) in a tight loop would do it for you.  You might have to worry about the cases where your qauntum expires during the execution of the loop, though.    Peace! -=- James


          If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
          Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
          DeleteFXPFiles & CheckFavorites (Please rate this post!)

          T Offline
          T Offline
          Tim Smith
          wrote on last edited by
          #5

          But doing such a thing makes you a bad windows user. Tim Smith I'm going to patent thought. I have yet to see any prior art.

          T 1 Reply Last reply
          0
          • N namaskaaram

            :~ getting a precise value in the microsecond range in windows is practically not possible ,taking into account that it handles many task at a time,since windows aint an real time os.....aint it????? "faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13

            A Offline
            A Offline
            Alexander M
            wrote on last edited by
            #6

            When the process and thread priority is at realtime level windows is almost like a real-time os. (not in timing, but you can implement a wait timer yourself by creating a loop and comparing the time differences!!!) Don't try it, just do it! ;-)

            1 Reply Last reply
            0
            • N namaskaaram

              :~ getting a precise value in the microsecond range in windows is practically not possible ,taking into account that it handles many task at a time,since windows aint an real time os.....aint it????? "faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13

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

              hem sorry mista rateepzzzzzzzzzz, i'm a bit off topic, but 1 ms is 1 milli-second for me, while 1 micro-second is written 1 µs...


              TOXCCT >>> GEII power
              [toxcct][VisualCalc]

              N 1 Reply Last reply
              0
              • T Tim Smith

                But doing such a thing makes you a bad windows user. Tim Smith I'm going to patent thought. I have yet to see any prior art.

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #8

                oh really ?! :~ do you know hardware programming ? :suss:


                TOXCCT >>> GEII power
                [toxcct][VisualCalc]

                J T 2 Replies Last reply
                0
                • L leatrop

                  I tried Sleep(1) but it looks like win xp and win 2000 wait for 10 ms instead. I could be wrong but if I do Sleep(10) then delay between characters I am sending exactly as with Sleep(1). I am not a Windows programmer, I am specialising in embedded real-time and particular in Unix systems and I know that often default kernel time resolution is 10 ms (eg. linux). What resolution windows Xp, 2000, 95, 98 have? Are they the same? What the best way to sleep for 1 ms? Thank you

                  A Offline
                  A Offline
                  Abu Mami
                  wrote on last edited by
                  #9

                  Have children.

                  1 Reply Last reply
                  0
                  • T toxcct

                    oh really ?! :~ do you know hardware programming ? :suss:


                    TOXCCT >>> GEII power
                    [toxcct][VisualCalc]

                    J Offline
                    J Offline
                    James R Twine
                    wrote on last edited by
                    #10

                    I think he was referring to my line:       "The best way is to run under a real-time OS...! :)"    Otherwise he would have said "bad Windows developer", not "user". :P    Peace! -=- James


                    If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                    Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                    DeleteFXPFiles & CheckFavorites (Please rate this post!)

                    1 Reply Last reply
                    0
                    • T toxcct

                      oh really ?! :~ do you know hardware programming ? :suss:


                      TOXCCT >>> GEII power
                      [toxcct][VisualCalc]

                      T Offline
                      T Offline
                      Tim Smith
                      wrote on last edited by
                      #11

                      Yes. I have been doing process control and industrial automation for many years. I have worked on my embedded processor systems (not just WinCE) and have written many device drivers for different hardware platforms (Z-80 using CPM, 68k running PDOS(?), 386 using only god knows what). Doing anything in a tight loop testing any type of flag without resolving to a kernel waitable object is a bad idea. It will lock other applications out of the CPU. Even spinlocks will only loop for a very limited amount of time prior to resorting to a kernel object. I would question the overall design if someone needed to do such a thing. There are cases where that level of timing is needed, but as already stated user mode isn't a good place to do such things. Thus, even if he could get it to work, it wouldn't be reliable in the real world. Tim Smith I'm going to patent thought. I have yet to see any prior art.

                      1 Reply Last reply
                      0
                      • T toxcct

                        hem sorry mista rateepzzzzzzzzzz, i'm a bit off topic, but 1 ms is 1 milli-second for me, while 1 micro-second is written 1 µs...


                        TOXCCT >>> GEII power
                        [toxcct][VisualCalc]

                        N Offline
                        N Offline
                        namaskaaram
                        wrote on last edited by
                        #12

                        like duh!!!!!:laugh:...... ahem...sorry mr toxxxxxxxxcit, i am not off thiz topic;) ,coz my bachelors happen to be in electronics &communication...... well i was wondering if microsec precision is possible with the QueryPerformance function taking into account that the windows aint an rtos system......my question seem to have just popped up when thiz question abt millisecond was put into,.....itz not the issue or misunderstanding of millisec,or pico sec,or nano sec or whatever!!!!!;) cheerz.....:-D "faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13

                        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