Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are registers shared among threads?

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

So how are registers shared among threads?

like image 733
justnobody Avatar asked Oct 13 '10 01:10

justnobody


1 Answers

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.

like image 193
Greg Hewgill Avatar answered Dec 31 '22 15:12

Greg Hewgill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!