What is exactly saved and restored in a context switch between two threads
When the context switching is between threads of the same process, all the non-volatile general purpose registers of the current thread are saved and those of the new thread are restored; volatile registers need to be saved only if the current thread execution has been interrupted by an interrupt. Registers of any co-processor used by the threads (e.g. floating point processor), should also be saved and restored If the switching is between threads of 2 processes, in addition to what is needed for a normal context switch, memory and IO management related changes should also be done; for e.g. memory protection needed by processes is achieved using page tables and page directory tables and each process has a unique page directory table address, which has to be changed when the process changes.