开发者

How do I obtain Sleep(0) like behaviour in Linux

开发者 https://www.devze.com 2023-03-16 07:55 出处:网络
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.

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.

What's开发者_开发问答 the best way to get Sleep(0) like behaviour in Linux?


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

精彩评论

暂无评论...
验证码 换一张
取 消