How are registers shared among threads?

前端 未结 1 1599
礼貌的吻别
礼貌的吻别 2021-02-04 04:23

I know that stacks are per thread, but registers are limited,like on IA32,only 8 registers.

So how are registers shared among threads?

1条回答
  •  野性不改
    2021-02-04 05:23

    Registers are used by the CPU when it's currently running a particular thread. When the OS decides to switch from one thread to another, the OS saves the current values of all the register into a private memory area specific to the first thread. Before the second thread starts running, the OS loads the values of all the registers from its saved area. This is called a context switch.

    0 讨论(0)
提交回复
热议问题