Search code examples
windowsmultithreadingwinapioperating-systempreemption

forced preemption on windows (occurs or not here)


Sorry for my weak english, by preemption I mean forced context (process) switch applied to my process.

My question is :

If I write and run my own program game in such way that it does 20 millisecond period work, then 5 millisecond sleep, and then windows pump (peek message/dispatch message) in loop again and again - is it ever preempted by force in windows or no, this preemption does not occur?

I suppose that this preemption would occur if I would not voluntary give control back to system by sleep or peek/dispatch in by a larger amount of time. Here, will it occur or not?


Solution

  • It can be interrupted by a driver at any time. The driver may signal another thread and then ask the OS to schedule/dispatch. The newly-ready thread may well run instead of yours.

    These desktop OS, like Windows, do not provide any real-time guarantees - they were not designed to provide it.