1sched_yield(2) System Calls Manual sched_yield(2)
2
3
4
6 sched_yield - yield the processor
7
9 Standard C library (libc, -lc)
10
12 #include <sched.h>
13
14 int sched_yield(void);
15
17 sched_yield() causes the calling thread to relinquish the CPU. The
18 thread is moved to the end of the queue for its static priority and a
19 new thread gets to run.
20
22 On success, sched_yield() returns 0. On error, -1 is returned, and er‐
23 rno is set to indicate the error.
24
26 In the Linux implementation, sched_yield() always succeeds.
27
29 POSIX.1-2008.
30
32 POSIX.1-2001.
33
35 If the calling thread is the only thread in the highest priority list
36 at that time, it will continue to run after a call to sched_yield().
37
38 POSIX systems on which sched_yield() is available define _POSIX_PRIOR‐
39 ITY_SCHEDULING in <unistd.h>.
40
41 Strategic calls to sched_yield() can improve performance by giving
42 other threads or processes a chance to run when (heavily) contended re‐
43 sources (e.g., mutexes) have been released by the caller. Avoid call‐
44 ing sched_yield() unnecessarily or inappropriately (e.g., when re‐
45 sources needed by other schedulable threads are still held by the
46 caller), since doing so will result in unnecessary context switches,
47 which will degrade system performance.
48
49 sched_yield() is intended for use with real-time scheduling policies
50 (i.e., SCHED_FIFO or SCHED_RR). Use of sched_yield() with nondetermin‐
51 istic scheduling policies such as SCHED_OTHER is unspecified and very
52 likely means your application design is broken.
53
55 sched(7)
56
57
58
59Linux man-pages 6.04 2023-03-30 sched_yield(2)