🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #8468

Re: Frienndly Sleep (not hogging the CPU)

#8468
From: Ali T. Ozer
Date: Sun, 10 Apr 1988 15:09
24 lines
1814 bytes
In article <662@wolf.UUCP> uzun@wolf.UUCP (Roger Uzun) writes:
> I was wondering if there was a friendly way for an amiga Process to
>Sleep for a period of time (in C).

You can use the Delay() function. Call Delay() with the number of 1/50 seconds:
Delay(50L) will put your process to sleep for one second. (By the way, don't
ever call Delay(0L) --- due to a bug in AmigaDOS, this might trash a disk.
Instead call: void MyDelay(d) unsigned long d; {if (d) Delay(d);}.

Another way is to use the timer device. Advantages:
 - You can have finer control (units smaller than 1/50 second)
 - You don't need to be running as an AmigaDOS process (Delay() is an AmigaDOS
   call and will not work from a task --- just from a process)
 - You can simultaneously wait for other things to happen: You can send a
   timer request, than do a Wait() on multiple signals; for instance, the
   timer port and your IDCMP port. Thus your program would wake up on either
   when the specified time has passed or when the user did something that
   requires attention, whichever comes first. 

Using the timer device isn't all that complicated; just a few more lines of
code than a Delay(). Check out LedClock from Fish 128 as a short example
of simple use of the timer device. 

Ali Ozer, ali@polya.stanford.edu
Technical Details
Message-ID: <2583@polya.STANFORD.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!bellcore!tness7!petro!swrinde!ut-sally!im4u!tut.cis.ohio-state.edu!mailrus!ames!pasteur!ucbvax!hplabs!decwrl!labrea!polya!ali
References: <662@wolf.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!bellcore!tness7!petro!swrinde!ut-sally!im4u!tut.cis.ohio-state.edu!mailrus!ames!pasteur!ucbvax!hplabs!decwrl!labrea!polya!ali
From: ali@polya.STANFORD.EDU (Ali T. Ozer)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Frienndly Sleep (not hogging the CPU)
Keywords: Sleep
Message-ID: <2583@polya.STANFORD.EDU>
Date: 10 Apr 88 15:09:14 GMT
References: <662@wolf.UUCP>
Reply-To: ali@polya.UUCP (Ali T. Ozer)
Organization: Stanford University
Lines: 24