What is saved in a context switch?

前端 未结 4 1238
孤城傲影
孤城傲影 2020-12-31 08:50

What is exactly saved and restored in a context switch between two threads

  • in the same process
  • between two processes
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-31 09:10

    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.

提交回复
热议问题