sched_yield()

QNX SDP8.0C Library ReferenceAPIDeveloper

Yield to other ready threads at the same priority

Synopsis:

#include <sched.h>

int sched_yield( void );

Library:

libc

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

Description:

The sched_yield() function checks 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. The sched_yield() function never yields to a lower-priority thread.

The sched_yield() function calls the kernel function SchedYield(), and may be more portable across realtime POSIX systems.

Note:
You should avoid designing programs that contain busy wait loops. If you can't avoid them, you can use sched_yield() to reduce the scheduling latency for other threads at a given priority level.

Returns:

This function always succeeds and returns zero.

Examples:

#include <stdio.h>
#include <stdlib.h>
#include <sched.h>

int main( void )
  {
    int i;

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

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

int fun()
  {
    int i;

    for( i = 0 ; i < 10 ; ++i )
      i += i;

    return( i );
  }

Classification:

POSIX 1003.1

Safety:
Cancellation pointNo
Signal handlerYes
ThreadYes
Page updated: