[Previous]
[Contents]
[Next]

Yield()

yield to another process at the same priority

Synopsis:

#include <sys/kernel.h>
void Yield( void );

Description:

The kernel function Yield() checks to see if other processes at the same priority as that of the calling process are READY to run. If so, the calling process yields to them and places itself at the end of the READY process queue. Yield() never yields to a lower priority process. Higher priority processes always force a yield the instant they become READY to run.


Note: You should avoid designing programs that contain busy wait loops. If its unavoidable, Yield() can be used to reduce the system load at a given priority level. Note that a program that calls Yield() in a tight loop will spend a great deal of time in the kernel, which will have a small effect on interrupt latency.

Examples:

#include <stdio.h>
#include <sys/kernel.h>

int main( void )
  {
    int i, sum;

    sum = 0;
    for( ;; ) {
      /* Process something... */
      for( i = 0 ; i < 100 ; ++i )
        sum += fun( i );

      /* Yield to anyone else at the same priority */
      Yield();
    }
    return( EXIT_SUCCESS );
  }

int fun(int i)
  {
    int j, k;

    k = 0;
    for( j = 0 ; j < i ; ++j )
      k += j;

    return( k );
  }

Classification:

QNX

Safety:
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

sleep()


[Previous]
[Contents]
[Next]