Suspends the execution of the current thread until the time-out interval elapses.
To enter an alertable wait state, use the
SleepEx
function.
Syntax
VOID WINAPI Sleep(
__in DWORD dwMilliseconds
);
Parameters
dwMilliseconds
[in]
The time interval for which execution is to be suspended, in milliseconds.
A value of zero causes the thread to relinquish the remainder of its
time slice to any other thread that is ready to run. If there are no
other threads ready to run, the function returns immediately, and the
thread continues execution.
Windows XP/2000:
A
value of zero causes the thread to relinquish the remainder of its time
slice to any other thread of equal priority that is ready to run. If
there are no other threads of equal priority ready to run, the function
returns immediately, and the thread continues execution. This behavior
changed starting with Windows Server 2003.
A value of INFINITE indicates that the suspension should not time out.
Return Value
This function does not return a value.
Remarks
This function causes a thread to relinquish the remainder of its time
slice and become unrunnable for an interval based on the value of dwMilliseconds
. The system clock "ticks" at a constant rate. If dwMilliseconds
is less than the resolution of the system clock, the thread may sleep for less than the specified length of time. If dwMilliseconds
is greater than one tick but less than two, the wait can be anywhere
between one and two ticks, and so on. To increase the accuracy of the
sleep interval, call the timeGetDevCaps
function to determine the supported minimum timer resolution and the timeBeginPeriod
function to set the timer resolution to its minimum. Use caution when calling timeBeginPeriod
, as frequent calls can significantly affect the system clock, system power usage, and the scheduler. If you call timeBeginPeriod
, call it one time early in the application and be sure to call the timeEndPeriod
function at the very end of the application.
After the sleep interval has passed, the thread is ready to run. If
you specify 0 milliseconds, the thread will relinquish the remainder of
its time slice but remain ready. Note that a ready thread is not
guaranteed to run immediately. Consequently, the thread may not run
until some time after the sleep interval elapses. For more information,
see
Scheduling Priorities
.
Be careful when using Sleep
in the following scenarios:
- Code that directly or indirectly creates windows (for example, DDE and COM CoInitialize
).
If a thread creates any windows, it must process messages. Message
broadcasts are sent to all windows in the system. If you have a thread
that uses
Sleep
with infinite delay, the system will deadlock.
- Threads that are under concurrency control. For example, an I/O
completion port or thread pool limits the number of associated threads
that can run. If the maximum number of threads is already running, no
additional associated thread can run until a running thread finishes. If
a thread uses Sleep
with an interval of zero to wait
for one of the additional associated threads to accomplish some work,
the process might deadlock.
For these scenarios, use
MsgWaitForMultipleObjects
or
MsgWaitForMultipleObjectsEx
, rather than
Sleep
.
Examples
For an example, see
Using Thread Local Storage
.
Requirements
Minimum supported client
Windows 2000 Professional |
Minimum supported server
Windows 2000 Server |
Header
Winbase.h (include Windows.h) |
Library
Kernel32.lib |
DLL
Kernel32.dll |
See Also
MsgWaitForMultipleObjects
MsgWaitForMultipleObjectsEx
Process and Thread Functions
SleepEx
Suspending Thread Execution
Threads
分享到:
相关推荐
sleepfunction.R
#### 舒睡功能说明(Good Sleep Function Instruction) 舒睡模式通过智能调节温度、风速等因素,创造一个更加舒适的睡眠环境。值得注意的是,在此模式下应取消换气功能,以避免频繁的风量变化影响睡眠质量。 ####...
sleep Function Section 10.20. Job-Control Signals Section 10.21. Additional Features Section 10.22. Summary Exercises Chapter 11. Threads Section 11.1. Introduction ...
#include <unistd.h> // for sleep function // 假设这里定义了用于控制电机的I/O端口和函数 void setPin(int pin, int value) { // 设置指定引脚的状态 } void stepMotor(int direction, int steps) { int ...
8. 睡眠功能(Sleep Function)和自动关机(Auto Power-Off): 为了延长电池寿命,某些钳式测试仪可能具备睡眠功能和自动关机功能。例如,CL130型号就配备了睡眠功能,当测试仪在一段时间内未进行任何操作时,它会...
3. Function Module 'Enque_Sleep' 的作用:Function Module 'Enque_Sleep' 是SAP系统提供的一个功能模块,专门用于处理会话休眠问题。通过执行此功能模块并传入适当的参数,可以试图唤醒处于休眠状态的会话。参数...
p&mJRJz VOL.30 I4 JULY 1983 COMMENTARY IIIThe function o f dream sleep Francis Crick* & Graemi M itchison*We propose that the function of dream sleep (more proper& rapid-&ye movement or REM sleep) LT...
前言 此教程是在vue中引入nosleep.js,并使用。 安装 nosleep.js npm install nosleep.js 引入 在main.js中引入 import NoSleep from nosleep.js/dist/NoSleep.min.js; Vue.prototype.$NoSleep ... function enableN
它将阻塞其周围上下文中的所有其他内容,直到设置完成标志:调用 done() 将上下文程序流恢复到正常的 asyc安装$ npm install stall用 var stall = require ( 'stall' )//template for a sleep functionvar sleep = ...
本文实例讲述了python中sleep函数用法。分享给大家供大家参考。具体如下: Python中的sleep用来暂停线程执行,单位为秒 #----------------------------------- ...# function. #-----------------
### JavaScript中的Sleep功能实现 在JavaScript编程中,有时我们需要实现某种形式的暂停或延迟执行的效果,这在异步操作、定时任务以及动画控制等方面尤为重要。然而,JavaScript本身并没有内置一个直接名为`sleep`...
sleep和msleep功能可以这样实现: function msleep ( n ) { Atomics . wait ( new Int32Array ( new SharedArrayBuffer ( 4 ) ) , 0 , 0 , n ) ;}function sleep ( n ) { msleep ( n * 1000 ) ;} 如果您需要usleep...
function sleep(numberMillis) { var now = new Date(); var exitTime = now.getTime() + numberMillis; while (true) { now = new Date(); if (now.getTime() > exitTime) { return; } } } ``` **优点:**...
function sleep(ms: number): Promise<void> { return new Promise((resolve) => setTimeout(resolve, ms)); } ``` 上述代码创建了一个新的Promise,它在给定的毫秒数`ms`后调用`resolve`,从而完成Promise。这样,...
function sleep(numberMillis) { var now = new Date(); var exitTime = now.getTime() + numberMillis; while (true) { now = new Date(); if (now.getTime() > exitTime) return; } } ``` 上述代码虽然看...
但是,这两个函数是异步的,在计时的过程中它们后面的代码还是会继续执行。...function sleep(sleepTime) { for(var start = Date.now(); Date.now() – start <= sleepTime; ) { } }sleep(500
function sleep(time) { const timeStamp = new Date().getTime(); const endTime = timeStamp + time; while (true) { if (new Date().getTime() > endTime) { return; } } } ``` 缺点:这种方法虽然简单,...
sleep函数延时函数:等待一段时间,再继续进行async function output() {let out = await sleep(1000);参考实
在C语言中,延时通常通过调用标准库函数如`sleep()`或`usleep()`实现,这些函数依赖于操作系统内核。但在没有操作系统或者需要精确控制延时的嵌入式系统中,汇编实现的延时函数就显得尤为重要。 在汇编中,延时通常...