sleep

Started by
2 comments, last by Calin 15 years ago
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

My project`s facebook page is “DreamLand Page”

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

I would love to change the world, but they won’t give me the source code.

) thanks
--
s.kwee didn't see that comming, reading.

My project`s facebook page is “DreamLand Page”

This topic is closed to new replies.

Advertisement