Jump to content
  • Advertisement
Sign in to follow this  
Calin

sleep

This topic is 3470 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What is the purpose of Sleep in Windows. i.e
Quote:
// This sleep keeps RakNet responsive #ifdef _WIN32 Sleep(30); #else usleep(30 * 1000); #endif
whats the meaning of 30

Share this post


Link to post
Share on other sites
Advertisement
Try Googling the documentation of the relevant functions.

As for the choice of the value 30, it was probably chosen through trial and error.

Don't forget to ask smart questions.

Share this post


Link to post
Share on other sites
Quote:
MSDN
Sleep Function

Suspends the execution of the current thread until the time-out interval elapses.

To enter an alertable wait state, use the SleepEx function.
Syntax
C++


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 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.

A value of INFINITE indicates that the suspension should not time out.

Return Value

This function does not return a value.


Well sleep in general used when as said in msdn you want to suspend execution of the thread from some time, I know for example when you have infinite loop it will take 100% of CPU (on single core), to prevent this you suspend the execution for 1ms so that the CPU can do something else in this time. Where in can be used else? I dunno, I think also if you need some resource that is taken by other process/thread you can suspend your execution for few ms (let cpu run other processes) and then request this resource once again (primitive example, and I'm not sure about it so correct me if I'm wrong)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!