i have used Sleep(n) in my code but am finding that is very inaccurate with errors upto 40 millisec. I need to replace this by a timer in some way by using a while loop or something. can anyone help me out by giving some simple code i can read ot understand how to use timers.any help would be great..
Comments
: i have used Sleep(n) in my code but am finding that is very inaccurate with errors upto 40 millisec. I need to replace this by a timer in some way by using a while loop or something. can anyone help me out by giving some simple code i can read ot understand how to use timers.any help would be great..
:
I do not know what precision you need, anyway you have to keep in mind that if you are working with a multitask system (like Windows), it is not so easy to wait for a very short time precisely. I have never tried this on a Windows OS and have no idea whether an error of 40ms is important or not.
I do not think using WM_TIMER messages would be more accurate because the delivery of window messages takes time and I read that the programmer should not expect the timer to be very accurate.
Steph
: : i have used Sleep(n) in my code but am finding that is very inaccurate with errors upto 40 millisec. I need to replace this by a timer in some way by using a while loop or something. can anyone help me out by giving some simple code i can read ot understand how to use timers.any help would be great..
: :
: I do not know what precision you need, anyway you have to keep in mind that if you are working with a multitask system (like Windows), it is not so easy to wait for a very short time precisely. I have never tried this on a Windows OS and have no idea whether an error of 40ms is important or not.
: I do not think using WM_TIMER messages would be more accurate because the delivery of window messages takes time and I read that the programmer should not expect the timer to be very accurate.
:
: Steph
The WM_TIMER message is sent with the lowest priority possible. It is very inaccurate.
Look at the performance api's (QueryPerformanceCounter and QueryPerformanceFrequence for example). They may help you.
You must also give your thread high priority, to prevent Windows as much as possible from interrupting your process. But that slows other processes down.
Another option may be to use the Pentium's RDTSC instruction, which allows for clock-tick accuracy.
Greets,
Eric Goldstein
http://www.gvh-maatwerk.nl
I tried that once and it brought the entire os to a screeching hault because the os didn't even get any time.
:
:
: I tried that once and it brought the entire os to a screeching hault because the os didn't even get any time.
:
[purple]shudn't that thread stop at a certain time and return control to os?
[/purple]
[hr][purple]~Donotalo()[/purple]
: : : You must also give your thread high priority, to prevent Windows as much as possible from interrupting your process. But that slows other processes down.
: :
: :
: : I tried that once and it brought the entire os to a screeching hault because the os didn't even get any time.
: :
: [purple]shudn't that thread stop at a certain time and return control to os?
: [/purple]
: [hr][purple]~Donotalo()[/purple]
:
:
There are about 56 different priority levels, based on the thread priority and the priority of it's parent process.
There is for example the THREAD_PRIORITY_TIME_CRITICAL priority which will cause the effects stober described.
But there's also THREAD_PRIORITY_HIGHEST and THREAD_PRIORITY_ABOVE_NORMAL. And more, MSDN describes them all.
Greets,
Eric Goldstein
http://www.gvh-maatwerk.nl