So I’ve been getting into a bit of assembly lately and I’m a beginner so i was wondering if someone could clarify something. I take it every process has it’s own set of registers, and each thread can modify these registers right?. How then do multiple threads use the same registers without causing clashes? Or does each thread have its own set of registers?
Share
A thread context switch involves saving the registers of the current execution context, and loading the registers with saved values from execution context begin switched to. (among other things). So each thread effectively has its own set of registers. Also its own stack, since ESP is one of the registers.
One way of thinking about this is that you get threads by saving off the current register state, and loading the registers with a new state. If that isn’t happening, then Its not a thread switch. If you are also switching to a different set of virtual address tables, then what you have is a process switch rather than a thread switch.
you say:
But this isn’t quite right. Each CPU core has a single set of registers. These registers are changed whenever the OS switches to a different thread. But there is only one thread executing in a CPU core at any one time. Processes don’t really have their own registers, processes own threads (or at least one thread), and threads have registers, or rather a place to keep the values for the registers while the thread is waiting for a CPU core to be available to run on.