david@doe.utoronto.ca (David Megginson) (02/21/91)
How can I have a process go to sleep under MiNT for a fixed amount of time? I would have harrassed Eric directly, but 1) this is of general interest; and 2) I already harrass him enough. David -- //////////////////////////////////////////////////////////////////////// / David Megginson david@doe.utoronto.ca / / Centre for Medieval Studies meggin@vm.epas.utoronto.ca / ////////////////////////////////////////////////////////////////////////
7103_2622@uwovax.uwo.ca (Eric Smith) (02/21/91)
> > How can I have a process go to sleep under MiNT for a fixed amount of > time? I would have harrassed Eric directly, but 1) this is of general > interest; and 2) I already harrass him enough. > There are at least three ways. In increasing order of complexity (and desireability): (1) sit in a for(;;) loop, checking the time and Syield()'ing until the time is up. The Syield's improve the performance, but you still end up hogging a far amount of time (2) use Fselect(x, 0L, 0L, 0L) (I think that's right -- I don't have the docs here). That sleeps for "x" milliseconds, x <= 32768; for longer waits, repeat as necessary. This is how the sleep() function is implemented in mntlib. (3) use Psignal() to set up a handler for SIGALRM, then use Talarm() to set an alarm for "n" seconds away, then Pause() to wait for the alarm signal to wake you up. This is the way it's usually done under Unix, and is definitely the best way to do it (I didn't in mntlib because I'm lazy -- doing it "right" requires checking to see how much time you actually slept, because you might have been woken up by a different signal; also, you have to watch out if there are other calls to Talarm()). PS: Don't worry about harassing me; we hosers have to stick together :-). -- Eric R. Smith email: Dept. of Mathematics eric.smith@uwo.ca University of Western Ontario 7103_2622@uwovax.bitnet