如何在睡眠操作系统级别执行? [英] how is sleep implemented at OS level?

查看:104
本文介绍了如何在睡眠操作系统级别执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只关心如何睡眠(时间以毫秒为单位)用C lib或基本上在操作系统级别实现..结果
我猜..结果
1)可以基于你做NOP的(不知道的while循环,如果睡眠时间是准确的处理器速度)..搜索结果
2)处理器,其中,u写一些值,处理器只是将暂停指定的任何特殊寄存器(这将是非常高效的处理器不能运行,即使其它程序)

I am just interested how sleep(time in ms) is implemented in C lib or basically at the os level..
I am guessing ..
1) may be the based on the processor speed you do a while loop of nop's ( not sure if the sleep time will be accurate)..

2) any special register in processor , where u write some value and the processor simply halts for specified time ( this would be very in efficient as the processor can't run even other programs)

任何线索?可能为C库源$ C ​​$ C能解释一下?我不是太讲究如何C正在实施它..只是一般如何休眠()函数实现疑惑。

any clues? probably C Lib source code can explain??? I am not too particular about how "C" is implementing it.. Just wondering in general how "sleep()" function is implemented..

推荐答案

睡眠()是在操作系统级别执行。当任务/线程/进程处于休眠状态的处理器不旋转。该特定线程放在一个等待队列,直到时间已在该点的线程将被放置在准备运行队列过期(线程不准备运行)。

Sleep() is implemented at the OS level. The processor doesn't spin when a task/thread/process is sleeping. That particular thread is put on a pending queue (the thread isn't ready to run) until the time has expired at which point the thread will be placed on the ready to run queue.

在此期间,其他线程准备运行将会运行。

In the meantime, other threads that are ready to run will be run.

只有当没有线程可以运行将操作系统进入空闲线程,直到一个硬件中断发生时在一般发出指令关闭(或置于低功耗状态反正)处理器。

Only if no threads are ready to run will the OS go into the idle thread, which in generally issues instructions to shutdown (or put into a low-power state anyway) the processor until an hardware interrupt occurs.

只有一个非常简单的系统(如最简单的嵌入式系统),可能睡眠()实际上被实现为没有什么比一个忙等待的循环。

Only for a very simple system (like the most simple of embedded systems), might Sleep() actually be implemented as nothing more than a busy wait loop.

不限操作系统教科书,如<一个href=\"http://www.pearsonhighered.com/educator/academic/product/0,,0136006639,00%2ben-USS%5F01DBC.html\">\"Modern由Tanenbaum的操作系统将覆盖这个非常详细 - 多pretty其中任何一个(甚至是一个古老的,价格便宜,使用)

Any operating system textbook, such as "Modern Operating Systems" by Tanenbaum will cover this in great detail - pretty much any of them (even an old, cheap, used one).

这篇关于如何在睡眠操作系统级别执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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