Forcing a context switch from the userland on Linux?

╄→尐↘猪︶ㄣ 提交于 2019-12-23 21:33:30

问题


Is it possible to advice the kernel to perform an immediate context switch to a different thread, bypassing the scheduler logic?

For example, if I've just created a thread/process with clone and I want to begin its execution straight away, renouncing the current context immediately, instead of waiting for the next time the kernel reschedules stuff.

Ideally, I'm looking for something identical to the thread_switch call on the Mach kernel.


回答1:


You shouldn't be trying to control context switches, as the kernel probably knows much better than you when to do it. Specially since a context switch is considered a costly operation (due to cache invalidation, mostly).

But, if you really need to force a scheduler cycle, you can use the sched_yield() system call.



来源:https://stackoverflow.com/questions/10362953/forcing-a-context-switch-from-the-userland-on-linux

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