I'd like to make a core of CPU keeping busy in 1 ms exactly. What is it doing is not important, for example, just do loop plus operation.
In Windows, in C++.
Give me related information for Linux is also great.
Asked
Active
Viewed 452 times
0

zhu
- 374
- 1
- 3
- 10
-
4You do realize that this isn't always possible right? Especially if the process gets context switched out. – Mysticial Aug 09 '12 at 02:45
-
3If you really need exactly 1ms then you are using the wrong operating system, use QNX (or some other real time operating system.) – Fantastic Mr Fox Aug 09 '12 at 02:57
-
What level of error is acceptable? Would 1ms +/- 20% be ok? A wait of 1ms "exactly" is physically meaningless, in that the actual length of a second is defined only statistically. The smaller the error you're willing to accept, the harder it will become to arrange. – Managu Aug 09 '12 at 02:57
1 Answers
1
You can always approximate busy work on a CPU (useless loop that spins and checks elapsed time over and over until 1ms has elapsed). Problem is that because of process management implemented in operating systems you are not guaranteed a 1ms complete timeslice. At any moment the CPU timer can interrupt your process and execute another (before your 1ms window is complete). For Linux and Windows the same applies.

Jesus Ramos
- 22,940
- 10
- 58
- 88