Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix x86线程上下文切换:为什么它';有必要将程序计数器存储到TCB中吗?_Unix_Context Switch - Fatal编程技术网

Unix x86线程上下文切换:为什么它';有必要将程序计数器存储到TCB中吗?

Unix x86线程上下文切换:为什么它';有必要将程序计数器存储到TCB中吗?,unix,context-switch,Unix,Context Switch,我试图理解线程上下文切换。我现在的一个抽象是一个线程将调用yield(),它被抽象为: yield() { new_thread = schedular.next_thread() switch(cur_thread, new_thread) house_keeping() } 和开关(当前线程、新线程)是: switch(cur_thread, new_thread) { store all registers into cur_TCB load TCB of new_t

我试图理解线程上下文切换。我现在的一个抽象是一个线程将调用
yield()
,它被抽象为:

yield() {
  new_thread = schedular.next_thread()
  switch(cur_thread, new_thread)
  house_keeping()
}
开关(当前线程、新线程)
是:

switch(cur_thread, new_thread) {
  store all registers into cur_TCB
  load TCB of new_thread
  ret
}
它说所有寄存器包括
%rip
都将被存储。但是如果我理解正确,在执行
switch
中的
ret
后,新堆栈上的
返回地址将弹出到
%rip

所以我的问题是:这是否意味着为新线程保存的
%rip
根本不被使用?(因为返回地址会立即加载到其中)为什么在上下文切换期间仍需要保存%rip