Skip to main content
GameDev.net gamedev.net
🔒 Locked

Sleep

Started by MSalley Dec 9, 2005 at 4:37 PM 6 replies 1k views
Original Post
MSalley
MSalley
what is the code for the sleep function again?
-Mat² §alley©-
MSalley
MSalley
n/m
-Mat² §alley©-
smart_idiot
smart_idiot
usleep(microseconds) [*nix]
Sleep(milliseconds) [windows]
sleep(seconds) [everywhere]
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other
Moe
Moe
On the same topic, what does Sleep(0) accomplish?
Ra
Ra
Quote:
Original post by Moe
On the same topic, what does Sleep(0) accomplish?

It yields control to the system, giving what remains of the current timeslice to the OS to use on another process or thread.
Ra
Sneftel
Sneftel
Yes, but at random intervals. Sleep(0) is a hint to the computer: "I really don't care if you want to pause me right now. So if you're going to do it, do it now, not in a couple of milliseconds." Sometimes useful to improve system responsiveness during heavy CPU usage.
illiyada
illiyada
It does that automatically (in preemptive schedulers).
However, if your program contains polling loops like
  while( ... )  {    ...    Sleep( 0 );  }

the Sleep call will allow scheduler to reschedule tasks in more optimal manner.
Otherwise it assumes that each and every CPU tick assigned for your task will be used properly (and not just burnt in tight polling loop).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.