Open System Services System Calls Reference Manual (G06.29+, H06.08+, J06.03+)

sched_yield(2) OSS System Calls Reference Manual
NAME
sched_yield - Signals a willingness to yield the processor to another thread in the current process
LIBRARY
G-series native OSS processes: /G/system/sysnn/zsptsrl
32-bit H-series and J-series OSS processes that use the POSIX User Thread Model library:
/G/system/zdllnnn/zputdll
64-bit H-series and J-series OSS processes that use the POSIX User Thread Model library:
/G/system/zdllnnn/yputdll
H-series and J-series OSS processes that use the Standard POSIX Threads library:
/G/system/zdllnnn/zsptdll
SYNOPSIS
[#include <sched.h>] #include <pthread.h> | #include <spthread.h>
/* pthread.h is required to use POSIX User Thread Model library */
/* spthread.h is required to use Standard POSIX Threads library */
int sched_yield(void);
DESCRIPTION
This function forces the calling thread to relinquish its processor until it again becomes the head
of its thread list. This function notifies the thread scheduler that the calling thread is willing to
release its processor to other threads of equivalent or greater scheduling precedence. (A thread
generally releases its processor to a thread of a greater scheduling precedence without calling
this function.) If no other threads of equivalent or greater scheduling precedence are ready to
execute, the calling thread continues.
This function can allow you to use knowledge of the details of an application to improve its per-
formance. If a thread does not call sched_yield( ), other threads might be given the opportunity
to run at arbitrary points (possibly even when the interrupted thread holds a required resource).
By making strategic calls to sched_yield( ), other threads can be given the opportunity to run
when the resources are free, which can sometimes improve performance by reducing contention
for resources.
Consider calling this function after a thread has released a resource (such as a mutex) that is
heavily used by other threads. This call can be especially important if the thread acquires and
releases the resource inside a tight loop.
Use this function carefully and sparingly, because misuse can cause unnecessary context switch-
ing, which increases overhead and degrades performance. For example, performance is degraded
if a thread yields while it holds a resource needed by the threads it is yielding to. Likewise,
yielding is pointless unless another thread is ready to run.
On systems running H06.21 or later H-series RVUs or J06.10 or later J-series RVUs, you can use
either the POSIX User Thread Model library or the Standard POSIX Threads library for threaded
applications.
To use this function in a threaded application that uses the POSIX User Thread Model library on
systems running H06.21 or later RVUs or J06.10 or later RVUs, you must perform all of the fol-
lowing tasks:
Include the pthread.h header file in the application.
Compile the application using the _PUT_MODEL_ feature test macro or equivalent
compiler command option.
Link the application to the zputdll library (/G/system/zdllnnn/zputdll).
On systems running H06.24 or later H-series RVUs or J06.13 or later J-series RVUs, you can use
the POSIX User Thread Model library with 32-bit or 64-bit threaded applications.
76 Hewlett-Packard Company 527186-023