How to let a thread block for a certain period of time without calling Sleep, without using timer and without taking much CPU time?
Posted on 2003-09-29 11:18:15 by optimus
Sleep/SleepEx are good... you could make an unsignaled event object and WaitForSingleObject if you really don't want to use Sleep, but unless you must wait on some object too, this would be sort of silly.
Posted on 2003-09-29 11:30:03 by f0dder
oic. i just re-wrote my program, and it works now.

btw: if i wanna have a high-accurate timer (e.g. , to let my code running every 1us), is it possible with out writing sth like a driver?
Posted on 2003-09-29 11:45:00 by optimus
hm, microsecond accuracy under a generic multitasking OS with PC hardware? Ick! - what would you need this for?
Posted on 2003-09-29 11:49:06 by f0dder
to implement real-time emulation in my 8051 emulator software.
(a traditional 8051 runs an instruction in 1us)
Posted on 2003-09-29 11:51:16 by optimus
hm, I think it would be pretty hard to achieve 1us accuracy... might be possible, as long as you don't try to run anything "critical".
Posted on 2003-09-29 11:56:57 by f0dder
yes, my app only requires soft-real-time, just as accurate as 1 us.
Posted on 2003-09-29 12:00:55 by optimus
waiting for a good solution...
Posted on 2003-09-29 12:14:37 by optimus
The only thing I can think of, off the top of my head, is creating a timer loop to get high-precision timing - this itself isn't an easy task, and has been debated here (and otherwhere) before. Such a loop probably won't do any Sleep(), so the app will be using 100% CPU time :)
Posted on 2003-09-29 12:19:02 by f0dder
It's not really possible to achieve such timing while still allowing the user to interact with the computer without disturbing the timing. Even with a modern high speed processor, the memory speed still limits you. You'll only be able to do this with a multi-processor system where the emulator runs with all interrupts disabled on the 2nd processor.
Posted on 2003-09-29 17:51:11 by Sephiroth3
This should be possible. MatLab has a utility called real time workshop, which can run a real-time program on windows. (not 1us time resolution, but 20us)
Posted on 2003-09-29 21:51:38 by optimus
Well, 20?s is an entirely different matter :P You could manage that by replacing the timer interrupt handler with your own, which runs the emulator and calls the original timer interrupt every so often. 1?s might be just a bit too much, but you could try.
Posted on 2003-09-30 07:42:31 by Sephiroth3