Advertisement Jump to content
Sign in to follow this  


This topic is 3562 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
// 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
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
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.

__in DWORD dwMilliseconds


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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!