Given a single core system that employs preemption for multitasking, how does the OS carry out thread interrupts when a user mode application is executing on the system? Since the processor is handling the user code when does it get a chance to ask the thread scheduler for context switch. Is it handled similarly to page faults? And if it is, how often it happens and isn't it causing a performance hit?
Read up on hardware interrupts.
The hardware timer issues periodic interrupts. When one happens, the CPU switches into kernel mode and executes a routine, the interrupt handler. That's where context switching takes place. When the CPU comes back from kernel to user mode, it returns control to a different thread than the one that the interrupt happened in. The state of the preempted thread is saved, naturally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With