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. Windows Forms
  4. Windows preemption

Windows preemption

Scheduled Pinned Locked Moved Windows Forms
help
5 Posts 3 Posters 2 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.
  • N Offline
    N Offline
    Nir sheffi
    wrote on last edited by
    #1

    Hi, I've encountered a problem where windows preempts for 16ms on a very simple code i'm running. In order to check it out I've written a simple code : while (1) { int t = timeGetTime(); Sleep(1); printf ("%d,",timeGetTime()-t); } the result i got where interesting - on some machines i got 1-2ms and on others 16ms. all machines run XP with no processes running in the background. I've tried running the same process in real-time and in normal mode - the results where the same.

    K D 2 Replies Last reply
    0
    • N Nir sheffi

      Hi, I've encountered a problem where windows preempts for 16ms on a very simple code i'm running. In order to check it out I've written a simple code : while (1) { int t = timeGetTime(); Sleep(1); printf ("%d,",timeGetTime()-t); } the result i got where interesting - on some machines i got 1-2ms and on others 16ms. all machines run XP with no processes running in the background. I've tried running the same process in real-time and in normal mode - the results where the same.

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      The code you have written would try to consume 100% of your CPU. When the windows system needs some CPU time it will pause your program and use the CPU. You can set your program to be a higher priority, but I wouldn't suggest that. I guess what I am wondering is what are you trying to accomplish? Ben

      1 Reply Last reply
      0
      • N Nir sheffi

        Hi, I've encountered a problem where windows preempts for 16ms on a very simple code i'm running. In order to check it out I've written a simple code : while (1) { int t = timeGetTime(); Sleep(1); printf ("%d,",timeGetTime()-t); } the result i got where interesting - on some machines i got 1-2ms and on others 16ms. all machines run XP with no processes running in the background. I've tried running the same process in real-time and in normal mode - the results where the same.

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        The parameter specified is not the actual time slept, but is the MINIMUM time that the thread should sleep. It's possible that the thread will sleep longer than the time speicified. Also, this is the minimum time that the thread will return to the ReadyToRUn state. It doesn't mean that the thread WILL run at the end of that time. Also, if the interval speicified is lower than the resolution of the system clock, the minimum time a thread will sleep IS the resolution of the system clock. I suggest checking out the docs on the Sleep[^] function. BTW, the "no processes running in the background" thing doesn't mean anything. Windows has can have over 150 threads running at the same time before you even see a Desktop. These are grouped into many different processes that are needed just to run Windows. So, this statement is actually false and quite impossible to achieve.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        N 1 Reply Last reply
        0
        • D Dave Kreskowiak

          The parameter specified is not the actual time slept, but is the MINIMUM time that the thread should sleep. It's possible that the thread will sleep longer than the time speicified. Also, this is the minimum time that the thread will return to the ReadyToRUn state. It doesn't mean that the thread WILL run at the end of that time. Also, if the interval speicified is lower than the resolution of the system clock, the minimum time a thread will sleep IS the resolution of the system clock. I suggest checking out the docs on the Sleep[^] function. BTW, the "no processes running in the background" thing doesn't mean anything. Windows has can have over 150 threads running at the same time before you even see a Desktop. These are grouped into many different processes that are needed just to run Windows. So, this statement is actually false and quite impossible to achieve.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          N Offline
          N Offline
          Nir sheffi
          wrote on last edited by
          #4

          Thanks, nevertheless, i see consistent behavior - on some machines i see 1-2ms and on others 16ms. the reason i did that experiment is that i have another simple code, without the sleep that preempts on some machines to 16ms and on others 1-2ms. this behavior is consistent.

          D 1 Reply Last reply
          0
          • N Nir sheffi

            Thanks, nevertheless, i see consistent behavior - on some machines i see 1-2ms and on others 16ms. the reason i did that experiment is that i have another simple code, without the sleep that preempts on some machines to 16ms and on others 1-2ms. this behavior is consistent.

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            So? Link the documentation said, it's system dependant. You have zero control over this. The Sleep duration specified is only specifies a requirement for the MINIMUM time that the thread must sleep, subject to many factors. There is nothing you can do to make the thread sleep for EXACTLY 1 to 2 ms.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            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