每个线程如何拥有CPU寄存器 [英] How each thread can have CPU registers

查看:1140
本文介绍了每个线程如何拥有CPU寄存器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我读过的几个地方,

Hi,

At several places I have read,

报价:

每个线程都有自己的CPU寄存器组和自己的堆栈

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



在这里,我可以了解堆栈,它是一个数据结构.但是线程如何拥有自己的CPU寄存器.它们的数量是固定的,并且系统中正在运行的线程数量是无限的.

关于



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

推荐答案

,因为它们是所谓执行上下文的一部分.基本上,当线程由于某种原因而挂起时,当前的计算机状态(所有寄存器,包括程序计数器,堆栈指针和标志值)都将作为线程与上下文一起保存.然后,实际的机器寄存器将免费供其他线程使用.恢复线程后,上下文将恢复到其原来的位置,并且甚至不必使线程知道它已被挂起.

如果这种情况没有发生,那么实际的寄存器将被共享,一个任务可能破坏另一个任务.也可能无法在其他Core甚至物理处理器上重新启动线程!
Because they are part of what is called the execution Context. Basically, when a thread is suspended for whatever reason, the current machine state (all registers, including program counter, stack pointer and flag values) are saves as part of the Context with the Thread. The actual machine registers are then free for other Threads to use. When a Thread is resumed, the Context is restored back to where it came from, and the Thread does not even have to be made aware that it was suspended.

If this didn''t occur, then the actual registers would be shared, and one task could corrupt them for another. It would also not be possible to restart a Thread on a different Core or even physical processor!


这篇关于每个线程如何拥有CPU寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆