什么是CPU寄存器和它们如何使用,特别是WRT多线程? [英] What are CPU registers and how are they used, particularly WRT multithreading?

查看:425
本文介绍了什么是CPU寄存器和它们如何使用,特别是WRT多线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面这个问题和我的回答主要是为了回应另一个问题的困惑。

This question and my answer below are mainly in response to an area of confusion in another question.

答案结束时,有一些问题WRT易失和线程同步,我不完全有信心 - 我欢迎评论和替代答案。问题的关键在于CPU寄存器以及如何使用它们。

At the end of the answer, there are some issues WRT "volatile" and thread synchronisation that I'm not entirely confident about - I welcome comments and alternative answers. The point of the question primarily relates to CPU registers and how they are used, however.

推荐答案

CPU寄存器是小数据区域存储在CPU的硅上。对于大多数体系结构,它们是所有操作发生的主要地方(数据从内存加载,操作和推回)。

CPU registers are small areas of data storage on the silicon of the CPU. For most architectures, they're the primary place all operations happen (data gets loaded in from memory, operated on, and pushed back out).

寄存器并拥有指令指针(它说明下一个指令)。当OS在另一个线程中交换时,所有的CPU状态,包括寄存器和指令指针,在某处被保存,有效地冻结线程的状态,当它下次恢复生命时。

Whatever thread is running uses the registers and owns the instruction pointer (which says which instruction comes next). When the OS swaps in another thread, all of the CPU state, including the registers and the instruction pointer, get saved off somewhere, effectively freeze-drying the state of the thread for when it next comes back to life.

还有更多的文档,当然,在所有的地方。 注册表上的维基百科上下文切换上的维基百科。编辑:或阅读Steve314的答案。 :)

Lots more documentation on all of this, of course, all over the place. Wikipedia on registers. Wikipedia on context switching. for starters. or read Steve314's answer. :)

这篇关于什么是CPU寄存器和它们如何使用,特别是WRT多线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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