Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sleep(...) and _sleep(...)

342 views
Skip to first unread message

Christian Mitchell

unread,
Sep 26, 1995, 3:00:00 AM9/26/95
to

We're currently porting a number of applications to run
'simultaneously' within an NT environment. Some of the
applications in question do not require their full time-
slice and thus we invoke the Sleep(0) function to free
up the processor. However some of the applications use
the _sleep(0) function instead and under Performance
Monitor these applications appear to use less processor
time, almost 0% as opposed to 87% for Sleep(0) apps.

I've read in one of the include header files that _sleep
is an obsolete function, could someone please explain
why _sleep(0) appears to free up the processor to such
a degree and also why is it now obsolete?

Also, if you highlight a MS-DOS window running a Sleep(0)
application, it raises its Performance Monitor line to
100% and every other process regardless drops to 0%. If
the MS-DOS window was running a _sleep(0) application,
this does not occur.


Regards,

Chris Mitchell.


Charles F. McDevitt

unread,
Sep 28, 1995, 3:00:00 AM9/28/95
to
In article <448ivc$e...@newsgate.als.co.uk>, c...@dev.als.co.uk says...

Are you sure you want to do a Sleep(0)? If no other task
needs the CPU at that instant, the CPU is given back to your app
for another timeslice or until the next call to Sleep(0).
If you are doing much processing at all between Sleep(0) calls,
you will still be using a lot of the system except when the
system is very busy and there is always some task waiting for
the CPU. (Note, if you don't do much work between Sleep(0) calls
this isn't a problem... Your app will look like it is using lots
of CPU whenever the system isn't busy, but it won't be taking it
from anyone else).

I'd suggest using Sleep(200), or something tuned to your
needs. By sleeping for a non-zero but still short time, you
will avoid being called in a hard loop, and guarantee lots of
time for other applications.


Jeffrey Altman

unread,
Sep 30, 1995, 3:00:00 AM9/30/95
to
In article <448ivc$e...@newsgate.als.co.uk>,
Christian Mitchell <c...@dev.als.co.uk> wrote:

Discussion of Sleep(0) vs _sleep(0) deleted.

The difference is that _sleep(0) results in a call
to Sleep(1). Sleep(0) obviously does not release the time slice
at all.

Jeffrey Altman * PO Box 220415 * Great Neck, NY * 11022-0415 * (516) 466-5495
NEW: OS/2 C-Kermit 5A(191):
ftp://kermit.columbia.edu/kermit/archives/cko191.zip
http://www.columbia.edu/kermit/cko191.html

0 new messages