加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

从linux内核中产生

发布时间:2020-12-14 01:19:15 所属栏目:Linux 来源:网络整理
导读:我在 Linux(3.4)中有一个实时线程.在某些条件下,我希望它将控制权放弃到具有相同优先级的其他线程,即使它还没有完成使用其当前时间片.我在考虑使用以下代码: if (condition) { resched_task(); cond_resched();} 但是,我没有看到代码中有其他人这样做,让我
我在 Linux(3.4)中有一个实时线程.在某些条件下,我希望它将控制权放弃到具有相同优先级的其他线程,即使它还没有完成使用其当前时间片.我在考虑使用以下代码:

if (condition) {
    resched_task();
    cond_resched();
}

但是,我没有看到代码中有其他人这样做,让我觉得还有其他(更好的?)方式.有没有标准的方法来做到这一点?

解决方法

您可以使用 sched_yield()函数生成剩余的时间片 as discussed here.

sched_yield() causes the calling thread to relinquish the CPU. The thread is moved to the end of the queue for its static priority and a new thread gets to run.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读