Given a uni processor architecture. A process X has code at memory location 10,000 , the PC(program counter) is pointing to it and executing instruction from there. A process Y has code at memory location 20,000. The OS(kernel) has its own code at some memory location. How does the PC change from process from code at location 10,000 or 10,050(after some time of execution),to the kernel location during a context switch to Process B ? Please let me know if you have the answer. Bamboozled by this question,don't know if I get onsite :(
Sigiloso
Kernel maintains a context structure for each thread. When the thread switch happens, kernel stores the values of all registers to this structure (to be used for next time). It then loads the contents of this structure of new thread on to the registers and the processor will start execution from eip. In fact, processor won't comes to know that thread has swapped, it just follows a very simple approach of reading instruction from eip and executes it. It is the kernel who is the mastermind behind thread swapping.