Unix to Windows Porting Dictionary for HPC

Links

Function List

sleep


Unix

header file: unistd.h

u_int sleep (u_int seconds);

Windows

header file: windows.h

VOID WINAPI Sleep(DWORD dwMilliseconds);

Purpose

Suspend a process executing for interval seconds (Unix) or milliseconds (Windows).

Discussion

The Unix and Windows sleep functions have the same intent but differ by the type of argument passed to the function and the spelling of the function name. The Unix function is spelling in all lower case while the Windows function is spelled with an uppercase 'S' with the rest in lowercase. We mention this because this is a minor typo that trips many people initially.

The time argument to the Unix function is in seconds while the Windows function's argument is in milliseconds. Conversion is easily done by multiplying the argument (Unix to Windows porting) by 1000.

The Unix sleep() returns zero on success after the sleep has completed. The Windows Sleep() does not return a value; execution continues when the function call has completed.

Example of Use in Windows

#include <windows.h>

DWORD time; /* previously u_int on Unix */

time = 5; /* for 5 seconds */
time = time * 1000; /* to convert to milliseconds on Windows */
Sleep(time);
/* code continues */
  
blog comments powered by Disqus