pthread_yield(3thr)pthread_yield(3thr)Namepthread_yield - Notifies the scheduler that the current thread is will‐
ing to release its processor to other threads of the same or higher
priority.
Syntax
#include <pthread.h>
void pthread_yield();
Arguments
None
Description
This routine notifies the scheduler that the current thread is willing
to release its processor to other threads of the same priority. (A
thread releases its processor to a thread of a higher priority without
calling this routine.)
If the current thread's scheduling policy (as specified in a call to
pthread_attr_setsched or pthread_setscheduler) is SCHED_FIFO, SCHED_RR,
or SCHED_OTHER, this routine yields the processor to other threads of
the same priority. If no threads of the same priority are ready to exe‐
cute, the thread continues.
This routine allows knowledge of the details of an application to be
used to increase fairness. It increases fairness of access to the pro‐
cessor by removing the current thread from the processor. It also
increases fairness of access to shared resources by removing the cur‐
rent thread from the processor as soon as it is finished with the
resource.
Call this routine when a thread is executing code that denies access
to other threads on a uniprocessor if the scheduling policy is
SCHED_FIFO.
Use pthread_yield carefully because misuse causes unnecessary context
switching, which increases overhead without increasing fairness. For
example, it is counter-productive for a thread to yield while it has a
needed resource locked.
Return Values
None
pthread_yield(3thr)