Click to See Complete Forum and Search --> : To boldy go were no thread has gone before


Martin vd Berg
April 26th, 1999, 03:40 AM
Hi there folks!

The SleepEx() system call can be used to suspend a thread. One parameter is a timeout value, specified in milliseconds.

However the resolution of this timeout seems to be about 10ms and I have to go beyond that.

I've tried SleepEx( 0, FALSE ) but than the thread just yields and will become active with no timeout.

Does anyone know a way to yield processor time with a higher resolution.


Thanks!

Martin van den Berg
High Tech Automation
The Netherlands
Martin.van.den.Berg@hta.nl

Emil
April 26th, 1999, 04:12 AM
As far as I know all operating systems have some timeslice it uses. There is no point in having shorter time slices because then the overhead from switching processes/threads would be so great that the thread/process would not be able to do any work.

Now, you have found that 10ms seams to be the "timeslice" for your computer. Seams resonable to me. And there is probably nothing you can do about it. But when you call SleepEx(0,FALSE) (according to MSDN documentation) you'll force a probable thread/process switch. If there is no other thread/process with the same priority, your thread will not "sleep".

So the question is, why should the thread sleep? To let other threads have a go or to delay execution for some time? SleepEx(0,FALSE) is good enough if you just want other threads to have a chance to execute, but if you really want that delay, then you're stuck with the 10ms I guess...

From MSDN (about SleepEx first parameter):
"A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution. "

---------------------------------------------
Emil Gustafsson
M.Sc. Computer Science
NTier Solutions AB
emil@ntier.se