[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug Report?



Rob Browning writes:

> Assuming I understand you correctly, and this is a program of your
> own, add a call to nanosleep(2) at an appropriate point.  You can tune
> the positioning and duration of the sleep to balance your needs.

> Note that what would be really nice here would be something like a
> "defer()" which just handed the rest of the processes timeslice back
> to the scheduler, but I don't know if such an animal exists.  Perhaps
> nice(1) will get the same effect.

> The reason to prefer defer() to nanosleep() is that if there are no
> other processes that need to do useful work, you don't want to be
> sleeping.

How about sched_yield?
Look in sched.h

In the POSIX.4 book, page 170, it describes sched_yield as:

It moves the calling process to the back of the line for its priority,
allowing any other processes at that priority to run.  Note that
sched_yield, when called by a priority 10 process, is not going to
allow a priority 9 process to run.  Only another priority 10 process
would get a chance.  If there were no priority 10 processes other than
the one calling sched_yield, then that process would immediately
resume its execution!

... {talks about a simple fork() example}

The point here is that sched_yield does something very simple.  It
merely moves a process to the end of the queue for its priority level.
 It does not guarantee that anything else is actually on that queue. 
It certainly does not guarantee <i>what</i> is on the queue.  For
example, some other process (unrelated to our sample program) might be
waiting to run - in which case, neither the parent nor the child would
be scheduled next.  Therefore, don't use sched_yield to enforce a
particular scheduling order.  It's too simple for that.  Use
semaphores instead.

Hope this helps...

Jeff McWilliams
jjmcwill@yahoo.com




==
Jeff McWilliams (jjmcwill@yahoo.com)
"The minstrel boy has gone to war,
 in the fields of death you'll find him" - author unknown


_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com


Reply to: