我如何获得睡眠(0)就像Linux中的行为 [英] How do I obtain Sleep(0) like behaviour in Linux

查看:187
本文介绍了我如何获得睡眠(0)就像Linux中的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows睡眠(0)产生线程控制而不指定最短时间,(见这里
但在Linux上,并从unistd.h中POSIX睡眠(0)只是忽略。

On Windows Sleep(0) yields thread control without specifying a minimum time, (see here) But on Linux and POSIX sleep(0) from unistd.h is just ignored.

什么是让睡眠(0)的行为就像在Linux中最好的方法是什么?

What's the best way to get Sleep(0) like behaviour in Linux?

推荐答案

尝试 SCHED_YIELD 从sched.h中,即只为你想做的事创建。

Try sched_yield from "sched.h", that is created just for what you want to do.

如果不出于什么原因工作上下文切换(如果任何线程在等待)。

If that doesn't work for whatever reason - try usleep(1) - That will yield at least 1 microsecond delay (may be more), which in turn triggers a context switch (if any thread is waiting).

这篇关于我如何获得睡眠(0)就像Linux中的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆