How to disable timer interruption for a while?

  • 2
    In the driver (kernel-mode) execute the assembly command [ cli ] [1], but you need to take into account that then you will need to restore the original value of the changed flag, otherwise the system will lose its operation. [1]: en.wikipedia.org/wiki/CLI_(x86) - gecube

1 answer 1

There are two ways. The first is to simply delete the timer. And when you need it again - create. The correct, normal way.

Method two - add the code to the very beginning of the timer handler

 if (mPaused) return 0; 

and accordingly a method for pausing

 void MakePause() { mPaused = true; } 

I think a similar method for removing from a pause write.

And the third way. If you know the exact time for which you want to disable the timer. To do this, the current timer is deleted, a new one is created with the required period. In its handler, you restore the old timer, and this one is deleted.

  • I meant the interruption of the Windows timer, that is, the processor time is given to the program that stopped the timer, and all other programs are waiting until it finishes the robot. Or something like a very high priority that will not allow other programs to use it. - nullptr
  • 2
    Well then, you have a very poorly worded question. Do you want to intervene in the system scheduler? The most reliable way is to upgrade to old versions of Windows with corporate multitasking. There you can. In modern systems, this can be done, but you have to go down to the kernel level. And what problem we solve, what was needed to do this? - KoVadim 3:49
  • you need to calculate the exact time of the algorithms and when you start the program, it constantly jumps. I decided that I need to either increase the priority of the program so that everything is idle, except for the running task, or to stop the timer interruption so that the scheduler cannot switch between processes. - nullptr
  • one
    and what's the point in the "exact time" if it will be performed on a live system? Either run the necessary code many times, and then average it, or use profilers. - KoVadim
  • one
    I agree with @KoVadim. Use the correct measurement methods (taking into account multithreading, the possibility of hibernation, etc.) and conduct a series of measurements. Anyway, an absolutely exact value cannot be obtained. - gecube