TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Patrick Haller
from: Peter Fitzsimmons
date: 1994-06-12 23:06:52
subject: Dos Programming - Os/2 S

PH> AFAIK there is/was a little bug (?). DosSleep (0L) 
 PH> won't release a complete timeslice, but DosSleep (1L) 
 PH> will. I'm not very sure about this, but after a few 
 PH> tests, I got very different results from those two 

Here's the beef:  DosSleep(0) releases the remainder of the current
timeslice to any thread of equal or higher priority,  if such a thread is
currently scheduled to be run.  If no such thread exists, DosSleep will
return immediately.

DosSleep(1) will cause the current thread to to marked as idle.  Any thread
that is ready to run will be,  even if it is a lower priority. The thread
that called DosSleep(1) will have to wait until it is its turn to be
scheduled again,  which could be quite some time if there are lots of other
threads waiting to run.  Additionally,  the values passed to DosSleep() are
rounded up to the next scheduler period (usually 32ms).  So DosSleep(1) is
the same as DosSleep(31).

Since the program in the foreground usually gets a "foreground
boost" from the scheduler,  it will have a higher priorty to similar
programs that are not in the foreground.  You can see,  therefore,  that
the likelihood of there actually being a thread (greater or equal in prty)
ready to run when DosSLeep(0) is called is not that large.

Moral of the story:  Call DosSleep(1) in your polling loops,  or else
"Pulse" will be unhappy.

 PH> When measuring 64 Threads usind DosSleep(1L), the CPU 
 PH> load raises to 17%. When doing the same with 
 PH> DosSleep(0L) to "pre-empt" the current thread 
 PH> voluntarily, the CPU load raises to 100%.

The "Pulse" program is not very useful,  but we are all stuck
programming for it, now that all the lusers are running it.

Pulse measures the amout of idle-time slices that are available,  and then
plots this upside down.  ie: When none of the idle-time slices are
available,  it plots 100%;  when all of the idle slices are available,it
plots 0%.  

What this does not show,  and which is much more interesting,  is if the
CPU is available for demand.  I can write an idle-time loop that will cause
Pulse to show 100%,  but the CPU is COMPLETELY available for any
"normal" priority thread that comes along.  In fact,  Pulse
relies on this -- it has such a loop inside of itself.  So when nothing
else needs your CPU,  Pulse is using all of it (and showing 0%). (Try
starting two copies of Pulse, one will show 50%!)


--- Maximus/2 2.01

* Origin: Beer bellies = great waist. (905)858-8488 (1:259/414)
SEEN-BY: 54/54 620/243 632/348 640/820 690/660 711/409 413 430 807 808 809
SEEN-BY: 711/934 712/353 623 713/888 800/1 2442/0
@PATH: 259/414 400 99 98 3615/50 229/2 2442/0 711/409 54/54 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.