线程上下文切换 Vs.进程上下文切换 [英] Thread context switch Vs. process context switch

查看:45
本文介绍了线程上下文切换 Vs.进程上下文切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我在这两种情况下到底做了什么?他们每个人的主要成本是多少?

Could any one tell me what is exactly done in both situations? What is the main cost each of them?

推荐答案

线程切换和进程切换的主要区别在于,线程切换时虚拟内存空间保持不变,进程切换时不转变.这两种类型都涉及将控制权移交给操作系统内核以执行上下文切换.切入和切出 OS 内核的过程以及切出寄存器的成本是执行上下文切换的最大固定成本.

The main distinction between a thread switch and a process switch is that during a thread switch, the virtual memory space remains the same, while it does not during a process switch. Both types involve handing control over to the operating system kernel to perform the context switch. The process of switching in and out of the OS kernel along with the cost of switching out the registers is the largest fixed cost of performing a context switch.

一个更模糊的代价是上下文切换与处理器缓存机制混乱.基本上,当您进行上下文切换时,处理器在其缓存中记住"的所有内存地址实际上都变得无用了.这里的一个很大区别是,当您更改虚拟内存空间时,处理器的转换后备缓冲区 (TLB) 或等效项会被刷新,从而使内存访问在一段时间内变得更加昂贵.这不会在线程切换期间发生.

A more fuzzy cost is that a context switch messes with the processors cacheing mechanisms. Basically, when you context switch, all of the memory addresses that the processor "remembers" in its cache effectively become useless. The one big distinction here is that when you change virtual memory spaces, the processor's Translation Lookaside Buffer (TLB) or equivalent gets flushed making memory accesses much more expensive for a while. This does not happen during a thread switch.

这篇关于线程上下文切换 Vs.进程上下文切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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