Windows preemption
-
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.
-
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.
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
-
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.
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 -
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, 2007Thanks, 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.
-
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.
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