Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

windows - How each thread can have CPU registers

At several places I have read,

Each thread has its own set of CPU registers and its own stack

Here, I can understand about stack, it's a data structure. But how thread can have its own CPU registers. They are fix in number and there are limitless number of threads are running in the system.

Regards

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, there are a fixed number of registers.

When the OS switches from 1 thread to another, it copies the state of the finishing thread, including the current values of all the registers into its descriptor, then copies the values from the the descriptor of another thread into the registers.

These descriptors are stored in RAM, although this is in part what Hyper Threading set out to fix, allowing 2 threads to be stored in a single CPU core at a time, but that is an entirely different discussion.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...