TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Paul Rider
from: Mike Bilow
date: 1995-05-06 14:51:42
subject: TimeSlices ??

Paul Rider wrote in a message to Mike Bilow:

 PR>         How can I give up time slices to other processes
 PR> while I'm in a loop simply waiting for something to happen ?
 PR> ...

 MB>       DosSleep(x);      /* Note that x > 0 should be used, such *
 MB>                          * as x = 1, due to a bug if x == 0     */


 PR>         Thanks Mike, that is exactly what I was looking
 PR> for... I've been going nuts watching my favorite programs(
 PR> currently dos [borlandc++ for os/2 due to arrive on Friday])
 PR> eat up the processor time, and bring the system to a crawl.
 PR> Frustrating as a programmer to see your programs act so 
 PR> greedily...         Paul Rider

While DosSleep() will work, I did not mean to imply that it is necessarily
good programming practice under OS/2 to use it in this way.  The problem is
that your application will actually be awakened on the expiration of the
sleep, and it is inefficient to have your application awakened over and
over again in order to determine that it has no work to do and can sleep
again.

The ideal approach under OS/2 is to have your application block while
waiting for something to happen, such as a keystroke or mouse click.  If
you have a program which makes a great deal of use of the processor, then
it is often more efficient to create a second thread to handle the
processor-intensive tasks and let the original thread handle the keyboard
and mouse.  This way, neither thread will actually run until it has work to
do: one thread will be blocked waiting for keyboard and mouse I/O, and the
other thread will be blocked waiting to be told (by a semaphore or similar
means) that the first thread is passing down work for it.

The goal is to make the application highly responsive to the user by
letting the user interact with a thread that does nothing other than
process user input, while consuming exactly the resources and CPU time
needed to do the job.
 
-- Mike


---
* Origin: N1BEE BBS +1 401 944 8498 V.34/V.FC/V.32bis/HST16.8 (1:323/107)
SEEN-BY: 105/42 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407
SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809
@PATH: 323/107 150 3615/50 396/1 270/101 105/103 42 712/515 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™.