|You probably can't reliably without going to extrodinary means. This is because Windows is not a Real time operating system, and at any stage your process could be preempted. However, the closest you can get is by calling
In reality this will sleep more than twenty milliseconds quite often, because it relinquishes your timeslice in the process scheduler, but it is the best you can do without doing something really hard.
Despite what my mis-spelling co-poster tells you, going to assembly language will not offer you any benefit over the above, because it is no less subject to pre-emption than anything else. He/she might argue that you do not relinquish your timeslice as above, however the same can be accomplished in C++ too.
void wait(DWORD ms);
static int cyclesPerMs; // Number of loop iterations per millisecond
int Timer::cyclesPerMs = -1;
const CALIBRATION_TICKS = 100000;
if(cyclesPerMs == -1)
// Calibrate timer
clock_t start = clock();
for(int i=0; i