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