[comp.unix.questions] Standard way to yield cpu

scott@next-8.gac.edu (Scott Hess) (11/26/90)

Is there any method under standard Unix to yield up the CPU so that other
tasks can run for a time?  I speculate that a call to sleep() with 0
timeout _might_ do it, but someone may just have optimized that part . . .
I could do testing, but it would not be very conclusive, as I'd have no
way of telling whether another task actually ran.

OS:  Unix over Mach on a NeXT.  BSD4.3 to the rest of the world.

Before you flame away, I am _not_ going to be doing polling.  Well, not
like you think.  I'm using a library built over select() to catch
incoming data on a pty line.  It would be advantageous to catch more
data from an emacs on the other end (it's a terminal emulator)
before doing redraws.  Of course, I'd not wait for something which
can blast data (like cat), but in the case of emacs, blast is not
exactly the word to use . . . (don't worry, vi does no better).

--
scott hess
scott@gac.edu
Independent NeXT Developer	(Stuart)
GAC Undergrad			(Horrid.  Simply Horrid.  I mean the work!)
<I still speak for nobody>

gwyn@smoke.brl.mil (Doug Gwyn) (11/27/90)

In article <SCOTT.90Nov25223409@next-8.gac.edu> scott@next-8.gac.edu (Scott Hess) writes:
>Is there any method under standard Unix to yield up the CPU so that other
>tasks can run for a time?  I speculate that a call to sleep() with 0
>timeout _might_ do it, but someone may just have optimized that part . . .
>I could do testing, but it would not be very conclusive, as I'd have no
>way of telling whether another task actually ran.

Basically, any system call provides a rescheduling opportunity.  If you
want to minimize the overhead, getpid() is the cheapest possible system
call.  However, other system calls such as select() will already be
providing reschedule opportunities in most cases.  If you really want
to delay the suspended process, sleep(nonzero) is the way to do it.