[Previous] [Contents] [Index] [Next]

Caution: This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.

SchedYield(), SchedYield_r()

Yield to other threads

Synopsis:

#include <sys/neutrino.h>

int SchedYield( void );

int SchedYield_r( void );

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

These kernel calls check to see if other threads at the same priority as that of the calling thread are ready to run. If so, the calling thread yields to them and places itself at the end of the ready thread queue for that priority. SchedYield() never yields to a lower priority thread. Higher priority threads always force a yield the instant they become ready to run. This call has no effect with respect to threads running at priorities other than the calling thread's.

The SchedYield() and SchedYield_r() functions are identical except in the way they indicate errors. See the Returns section for details.


Note: Instead of using these kernel calls directly, consider calling sched_yield().

Avoid designing programs that contain busy-wait loops using SchedYield() to timeslice. If this is unavoidable, you can use SchedYield() to reduce the system load at a given priority level. Note that a program that calls SchedYield() in a tight loop will spend a great deal of time in the kernel, which will have a small effect on scheduling interrupt latency.

Blocking states

These calls don't block. However, if other threads are ready at the same priority, the calling thread is placed at the end of the ready queue for this priority.

Returns:

The only difference between these functions is the way they indicate errors:

SchedYield()
If an error occurs, -1 is returned and errno is set. Any other value returned indicates success.
SchedYield_r()
EOK is returned on success. This function does NOT set errno. If an error occurs, any value in the Errors section may be returned.

Classification:

QNX Neutrino

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

sched_yield(), SchedGet(), SchedSet()


[Previous] [Contents] [Index] [Next]