Sleep

From Green software

(Difference between revisions)
Jump to: navigation, search
(New page: A computer program (process, task, or thread) may sleep, which places it into an inactive state for a period of time. Eventually the expiration of an interval timer, or the receipt of a si...)
Line 35: Line 35:
} while (externalVar > 10);
} while (externalVar > 10);
 +
== References ==
 +
[http://malektips.com/xp_dos_0002.html batch file sleep command]<br />
 +
[http://ibm5.ma.utexas.edu/cgi-bin/man-cgi?sleep+3 UNIX Man Page - SLEEP(3)]</ref> (For more precise sleep times one can use the <code>usleep()</code> function.)<br />
 +
[http://www.manpagez.com/man/3/usleep/ UNIX Man Page - usleep(3)]<br />
 +
[http://www.jguru.com/faq/view.jsp?EID=47127 Sleep vs. Wait (1)]<br />
 +
[http://stackoverflow.com/questions/1036754/difference-between-wait-and-sleep Sleep vs. Wait (2)]<br />
 +
[http://msdn.microsoft.com/en-us/library/ms686298(VS.85).aspx MSDN Library Reference - Sleep()]<br />
-
== Cases ==
+
== Sources ==
-
 
+
This best practice was recognized as such by IT professionals, described in [[Energy efficient software (Master Thesis)|''Energy efficient software'']].
-
== See Also ==
+
-
 
+
-
== References ==
+
-
<nowiki>
+
-
<ref>[http//malektips.com/xp_dos_0002.html batch file sleep command]</ref>
+
-
<ref>[http//ibm5.ma.utexas.edu/cgi-bin/man-cgi?sleep+3 UNIX Man Page - SLEEP(3)]</ref> (For more precise sleep times one can use the <code>usleep()</code> function.)
+
-
<ref>[http//www.manpagez.com/man/3/usleep/ UNIX Man Page - usleep(3)]</ref>
+
-
<ref>[http//www.jguru.com/faq/view.jsp?EID=47127 Sleep vs. Wait (1)]</ref>
+
-
<ref>[http//stackoverflow.com/questions/1036754/difference-between-wait-and-sleep Sleep vs. Wait (2)]</ref>
+
-
http//msdn.microsoft.com/en-us/library/ms686298(VS.85).aspx MSDN Library Reference - Sleep()
+
-
</nowiki>
+

Revision as of 14:10, 15 September 2010

A computer program (process, task, or thread) may sleep, which places it into an inactive state for a period of time. Eventually the expiration of an interval timer, or the receipt of a signal or interrupt causes the program to resume execution.

When sleep is properly used, a CPU can reach a high utilization which is good for energy efficiency.

Putting applications in a state of sleep is already common practice in software for mobile platforms.

Contents

Low Level Functionality

Sleep causes the thread or process to enter the Not Runnable state. This allows the CPU to suspend the thread or process and continue executing other threads or processes until the sleep has finished, and the thread or process is allowed to continue executing. The sleep system call is non-interruptible, which differs from the Wait system call, which can be interrupted. Wait is mostly used in multi-threaded platforms.

Usage

A typical sleep system call takes a time value as a parameter, specifying the minimum amount of time that the process is to sleep before resuming execution. The parameter typically specifies seconds, although some operating systems provide finer resolution, such as milliseconds or microseconds.

Windows

On Windows 2000 and newer, the Sleep() function takes a single parameter of the number of milliseconds to sleep.

The sleep() function is included in the kernel32.dll, but no sleep command (executable) is natively available for scripts (batch files). It can be found in collections of Windows utilities like Windows 2003 Resource Kit.

Unix

On Unix-like operating systems, the sleep() function is called providing a single parameter of type unsigned integer of the number of seconds to sleep.

C/C++ Examples

In Windows OS:

   while (myInt <= 100)
   {
       Sleep(2*1000);  // Sleep for 2 seconds
   }


In Unix:

   do
   {
       sleep(2);  // Sleep for 2 seconds
   } while (externalVar > 10);

References

batch file sleep command
UNIX Man Page - SLEEP(3)</ref> (For more precise sleep times one can use the usleep() function.)
UNIX Man Page - usleep(3)
Sleep vs. Wait (1)
Sleep vs. Wait (2)
MSDN Library Reference - Sleep()

Sources

This best practice was recognized as such by IT professionals, described in Energy efficient software.

Personal tools