Context switching when a thread invokes a system call

可紊 提交于 2019-12-11 04:02:54

问题


I have a process with multiple threads. If one of my threads invokes a system call like gettimeofday(), does the kernel only switch that thread out of context to service the system call, or does it switch the entire process (and all other threads) out of context?


回答1:


Most system calls may involve a context switch (if other tasks are runnable) and switch the processor's state to kernel mode.

But gettimeofday (and e.g. getpid()) are unusual. with recent kernels they use VDSO to avoid it (and even to avoid the syscall or sysenter instruction to switch to kernel mode).




回答2:


To the linux kernel, a thread is a process. So the kernel has no interest in the other threads of your process when one of them makes a syscall.



来源:https://stackoverflow.com/questions/9728421/context-switching-when-a-thread-invokes-a-system-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!